简体   繁体   English

R:xlim,ylim和zlim不适用于rgl.plot3d

[英]R: xlim, ylim and zlim not working for rgl.plot3d

I'm trying to create a 3d scatter plot using the following script: 我正在尝试使用以下脚本创建三维散点图:

d <- read.table(file='myfile.dat', header=F)
plot3d(
    d,
    xlim=c(0,20),
    ylim=c(0,20),
    zlim=c(0,10000),
    xlab='Frequency',
    ylab='Size',
    zlab='Number of subgraphs',
    box=F,
    type='s',
    size=0.5,
    col=d[,1]
)
lines3d(
    d,
    xlim=c(2,20),
    ylim=c(0,20),
    zlim=c(0,10000),
    lwd=2,
    col=d[,1]
)
grid3d(side=c('x', 'y+', 'z'))

Now for some reason, R is ignoring the range limits I've specified and is using arbitrary values, messing up my plot. 现在由于某种原因,R忽略了我指定的范围限制并使用任意值,弄乱了我的情节。 I get no error when I run the script. 运行脚本时没有错误。 Does anybody have any idea what's wrong? 有人知道什么是错的吗? If required, I can also post an image of the plot that is created. 如果需要,我还可以发布创建的图表的图像。 The data file is given below: 数据文件如下:

myfile.dat MYFILE.DAT

11    2    2
NA    NA    NA
10    2    2
NA    NA    NA
13    2    1
NA    NA    NA
15    2    1
NA    NA    NA
5    2    11
5    3    10
5    4    16
5    5    34
5    6    102
5    7    294
5    8    682
5    9    1439
5    10    2646
5    11    3615
5    12    2844
5    13    1394
NA    NA    NA
4    2    10
4    3    4
4    4    4
4    5    10
4    6    38
4    7    132
4    8    396
4    9    976
4    10    2121
4    11    4085
4    12    6261
4    13    6459
4    14    4238
4    15    1394
NA    NA    NA
7    2    3
NA    NA    NA
6    2    2
NA    NA    NA
9    2    8
9    3    6
9    4    4
9    5    5
NA    NA    NA
8    2    4
8    3    10
8    4    22
8    5    52
8    6    126
8    7    264
8    8    478
8    9    729
8    10    943
8    11    754
8    12    382
NA    NA    NA

The help page, ?plot3d says "Note that since rgl does not currently support clipping, all points will be plotted, and 'xlim', 'ylim', and 'zlim' will only be used to increase the respective ranges." 帮助页面?plot3d说“请注意,由于rgl目前不支持剪切,因此将绘制所有点,并且'xlim','ylim'和'zlim'将仅用于增加相应的范围。” So you need to restrict the data in the input stage. 因此,您需要限制输入阶段的数据。 (And you will need to use segments3d instead of lines3d if you only want particular ranges that are inside the plotted volume.) (如果您只想要绘制体积内的特定范围,则需要使用segments3d而不是lines3d。)

d2 <- subset(d,  d[,1]>0 & d[,1] <20 & d[,2]>0 & d[,2] <20  & d[,3]>0 & d[,3]<10000 ])
plot3d(
    d2[, 1:3],  # You can probably use something more meaningful,
    xlim=c(0,20),
    ylim=c(0,20),
    zlim=c(0,10000),
    xlab='Frequency',
    ylab='Size',
    zlab='Number of subgraphs',
    box=F,
    type='s',
    size=0.5,
    col=d[,1]
)

(I did notice that when the range was c(0,10000) that the size of the points was pretty much invisible. and further experimentation suggest that the great disparity in ranges is going to cause furhter difficulties in keeping the ranges at 0 on the low side if you increase the size to the point where it is visible. If you make the points really big , they expand the range to accommodate the overlap beyond the x=0 or y=0 planes.) (我确实注意到,当范围是c(0,10000)时,点的大小几乎是不可见的。进一步的实验表明,范围的巨大差异将导致将范围保持为0的困难。如果你将尺寸增加到可见的点,那么偏低。如果你使这些点真的很大,它们会扩大范围以适应超出x = 0或y = 0平面的重叠。)

As DWin said, lines3d does not handle *lim arguments. 正如DWin所说, lines3d不处理* lim参数。 From the help page, "... Material properties (see rgl.material), normals and texture coordinates (see rgl.primitive)." 在帮助页面中,“......材料属性(参见rgl.material),法线和纹理坐标(参见rgl.primitive)。”
So use some other function, or perhaps you could retrieve the existing limits from your plot3d call and use those to scale your data prior to plotting? 那么使用其他一些功能,或者你可以从plot3d调用中检索现有的限制,并在绘图之前使用它们来扩展数据?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM