缺少价值 - 极地情节

时间:2013-06-22 01:30:09

标签: r

数据集:两个双变量不等的观察结果:

g_d g_a s_d s_a
2   27.75047815 2   27.75047815
2   27.75047815 2   27.75047815
3   27.75047815 2   27.75047815
3   27.75047815 2   27.75047815
3   27.75047815 2   27.75047815
5   27.75047815 2   27.75047815
6   27.75047815 2   27.75047815
8   27.75047815 2   27.75047815
9   27.75047815 2   27.75047815
10  27.75047815 2   27.75047815
3   17.19518769 2   27.75047815
3   13.21767851 2   27.75047815
4   13.21767851 3   27.75047815
4   13.21767851 3   27.75047815
5   13.21767851 3   27.75047815
6   13.21767851 3   27.75047815
6   13.21767851 3   27.75047815
6   13.21767851 3   27.75047815
7   13.21767851 3   27.75047815
8   13.21767851 3   27.75047815
9   13.21767851 3   27.75047815
9   13.21767851 3   27.75047815
11  13.21767851 3   27.75047815
11  13.21767851     
14  13.21767851     
14  13.21767851     
14  13.21767851     
15  13.21767851     
16  13.21767851     
17  13.21767851     
24  13.21767851     
2   30.90877312     
2   30.90877312     
2   30.90877312     
2   30.90877312     
2   30.90877312     
3   30.90877312     
3   30.90877312     
3   30.90877312     

我正在尝试使用以下命令在相同的绘图窗口中并排绘制2个极坐标图

代码:

d = read.table("D:/POLAR_1.txt", sep="\t", header=T)
attach(d)
summary(d)
library(plotrix)
par(mfrow=c(1,2))

对于第一极图:

polar.plot(NA, NA, clockwise=TRUE, rp.type="", start=90,radial.lim=c(0, 35), 
radial.cex=0.3, box.radial=TRUE, show.grid.labels=1, boxed.radial=FALSE)

polar.plot(g_d, g_a, clockwise=TRUE, rp.type="s", start=90, point.symbols=19, 
show.grid.labels=3, par(cex=0.8), add=TRUE)

对于第二极图:

polar.plot(NA, NA, clockwise=TRUE, rp.type="", start=90,radial.lim=c(0, 35), 
radial.cex=0.3, box.radial=TRUE, show.grid.labels=1, boxed.radial=FALSE, add=TRUE)

polar.plot(s_d, s_a, clockwise=TRUE, rp.type="s", start=90, point.symbols=19, 
show.grid.labels=3, par(cex=0.8), add=TRUE)

结果:我可以得到第一个情节,但是对于第二个情节我得到以下信息:

错误报告:

Error in if (grid.pos[1] < radial.lim[1]) grid.pos <- grid.pos[-1] : 
  missing value where TRUE/FALSE needed

的问题?

由于第二个数据集有一些缺失值(因为观察较少),所以我收到此错误。所以,想知道如何处理这个错误。

1 个答案:

答案 0 :(得分:1)

试试这个例子:

enter image description here

library(plotrix)

par(mfrow=c(1,2))
polar.plot(NA, NA, clockwise=TRUE, rp.type="", start=90,radial.lim=c(0, 35), 
           radial.cex=0.3, box.radial=TRUE, show.grid.labels=1, boxed.radial=FALSE)
polar.plot(g_d, g_a, clockwise=TRUE, rp.type="s", start=90, point.symbols=19, 
           show.grid.labels=3, par(cex=0.8), add=TRUE)

## here remove add=TRUE      
polar.plot(NA, NA, clockwise=TRUE, rp.type="", start=90,radial.lim=c(0, 35), 
             radial.cex=0.3, box.radial=TRUE, show.grid.labels=1, boxed.radial=FALSE)
## use na.omit to remove missing values
polar.plot(na.omit(s_d), na.omit(s_a), clockwise=TRUE, rp.type="s", start=90, point.symbols=19, 
           show.grid.labels=3, par(cex=0.8), add=TRUE)