R: xlim, ylim and zlim do not work for rgl.plot3d

I am 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 constraints I specified and using arbitrary values, messing up my plot. I am not getting an error when running the script. Does anyone know what happened? If required, I can also post an image of the generated plot. The data file is shown below:

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

      

+3


source to share


2 answers


The help page ?plot3d

says "Note that since rgl does not currently support cropping, all points will be plotted, and" xlim "," ylim "and" zlim "will only be used to increase the corresponding ranges." Therefore, you need to restrict the data at the entry stage. (And you will need to use segments3d

lines3d instead if you only want specific ranges that are within the graphics volume.)

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 noticed that when the range was c (0.10000), the size of the points was almost invisible. Further experiments show that a large disparity in the ranges will make it difficult to keep the ranges at 0 on the lower side if you increase the size to a point. where it is visible. If you make the points really large, they expand the range to place the overlap outside the x = 0 or y = 0 planes.)

+2


source


As DWin said, lines3d

doesn't handle * lim arguments. On the reference page "Material Properties (see Rgl.material), Normals, and Texture Coordinates (see Rgl.primitive)".
So, use some other function, or perhaps you can get the existing constraints out of your call plot3d

and use them to scale your data prior to plotting?



0


source







All Articles