添加一个传奇的RGL 3D绘图 [英] Adding a legend to an rgl 3d plot

查看:2196
本文介绍了添加一个传奇的RGL 3D绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请使用RGL颜色图例显示的颜色是指3D绘图哪个类(称为cut.rank):

I am trying to draw a 3d plot using rgl with colors legend indicating which color refer to which class (called 'cut.rank'):

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))
) 

但我似乎无法得到传说中显示的情节了。 (见附件图) 任何想法?

But I can't seem to get the legend showing up in the plot. (See attached plot) Any idea ?

推荐答案

我不知道该 colkey 选项适用于 PLO​​T3D 功能。您可以使用 legend3d ,而不是增加一个传奇人物的样子,你会在正常的2D绘图:

I'm not sure the colkey option applies to the plot3d function. You can use legend3d instead to add a legend the way you would in normal 2d plots:

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')

更新: colkey 是一个参数 scatter3D PLO​​T3D 包(不一样的 PLO​​T3D 功能在 RGL 包)。您可以使用此还有:

Update: colkey is an argument to scatter3D in the plot3D package (not the same as the plot3d function in the rgl package). You can use this as well:

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))

这篇关于添加一个传奇的RGL 3D绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆