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. 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
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." 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.)
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With