[英]3d scatterplot in R using rgl plot3d - different size for each data point?
我在用
plot3d(x,y,z, col=test$color, size=4)
使用R繪制我的數據集的三維散點圖,但使用rgl
, size
參數只需要一個大小。
是否可以為每個數據點設置不同的大小,可能是另一個庫,還是有一個簡單的解決方法?
謝謝你的想法!
這是Etienne建議的同樣的解決方法。 關鍵的想法是設置圖,然后單獨調用points3d()
來繪制每個尺寸類中的點。
# Break data.frame into a list of data.frames, each to be plotted
# with points of a different size
size <- as.numeric(cut(iris$Petal.Width, 7))
irisList <- split(iris, size)
# Setup the plot
with(iris, plot3d(Sepal.Length, Sepal.Width, Petal.Length, col=Species, size=0))
# Use a separate call to points3d() to plot points of each size
for(i in seq_along(irisList)) {
with(irisList[[i]], points3d(Sepal.Length, Sepal.Width,
Petal.Length, col=Species, size=i))
}
(FWIW,似乎沒有辦法讓plot3d()
直接執行此操作。問題是plot3d()
使用輔助函數material3d()
來設置點大小,如下所示, material3d()
只想取單個數值。)
material3d(size = 1:7)
# Error in rgl.numeric(size) : size must be a single numeric value
為了防止其他人在這些年后偶然發現,現在完全有可能將變量傳遞給size參數,例如with(test, plot3d(x,y,z, col=test$color, size=test$size))
。
實際上,您可以對輸入大小的數據進行操作,它也可以工作。 我成功地用size = x/(max(x,na.rm=TRUE)-min(x,na.rm=TRUE))
的線來制作基本尺寸比。
雖然material3d
確實只接受單個數值,但是應該事先評估在with語句中輸入大小的表達式或變量,因此material3d
應該仍然只能看到每個繪制點的單個大小值。 自從我花了一個多小時左右擺弄這里發布的解決方法之后才意識到這是不必要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.