2015-01-15 21 views
6

Tôi cố gắng để vẽ một âm mưu 3d sử dụng RGL với màu sắc huyền thoại chỉ có màu tham khảo mà lớp (gọi là 'cut.rank'):Thêm một huyền thoại cho một 3d cốt truyện RGL

plot3d(
data.focus$normalized.price_shipping, 
data.focus$seller_feedback_score_rank, 
data.focus$seller_positive_feedback_percent_rank, 
col=as.factor(data.focus$cut.rank), 
size=1, 
type='s', 
xlab = 'Normalized Price', 
ylab = 'Seller Feedbacl Score Rank', 
zlab = 'Seller Positive Feedback Percent Rank', 
main = 'Rank By Price, Feedback score and Positive Feedback Score', 
sub = 'Search Rank has 3 colored levels', 
colkey = list(length = 0.5, width = 0.5, cex.clab = 0.75)) 
) 

Nhưng tôi có thể dường như không nhận được huyền thoại hiển thị trong cốt truyện. (Xem ô đính kèm) Bất kỳ ý tưởng nào? enter image description here

Trả lời

10

Tôi không chắc chắn tùy chọn colkey áp dụng cho chức năng plot3d. Bạn có thể sử dụng legend3d thay vì thêm một huyền thoại theo cách bạn sẽ trong lô 2d bình thường:

library(rgl) 

#dummy data 
set.seed(1) 
x <- cumsum(rnorm(100)) 
y <- cumsum(rnorm(100)) 
z <- cumsum(rnorm(100)) 
cuts = cut(x = 1:length(x), breaks = 3) 

# open 3d window 
open3d() 

# resize window 
par3d(windowRect = c(100, 100, 612, 612)) 

# plot points 
plot3d(x, y, z, 
     col=rainbow(3)[cuts], 
     size = 2, type='s') 

# add legend 
legend3d("topright", legend = paste('Type', c('A', 'B', 'C')), pch = 16, col = rainbow(3), cex=1, inset=c(0.02)) 

# capture snapshot 
snapshot3d(filename = '3dplot.png', fmt = 'png') 

enter image description here

Cập nhật: colkey là một lập luận để scatter3D trong gói plot3D (không giống như các plot3d chức năng trong gói rgl). Bạn có thể sử dụng cũng như:

library(plot3D) 
scatter3D(x,y,z, col = rainbow(3)[cuts], colvar = NA, colkey = F, pch = 16) 
legend("topright", paste('Type', c("A", "B", "C")), pch = 16, col = rainbow(3), cex=1, inset=c(0.02,0.2)) 

enter image description here

Các vấn đề liên quan