【问题标题】:Adding a legend to an rgl 3d plot向 rgl 3d 绘图添加图例
【发布时间】:2015-01-15 06:59:53
【问题描述】:

我正在尝试使用带有颜色图例的 rgl 绘制 3d 图,指示哪种颜色指的是哪个类(称为“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))
) 

但我似乎无法让传说出现在情节中。 (见附图) 有什么想法吗?

【问题讨论】:

    标签: r plot 3d rgl


    【解决方案1】:

    我不确定colkey 选项是否适用于plot3d 函数。您可以使用legend3d 来添加图例,就像在普通二维图中一样:

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

    更新:colkeyplot3D 包中scatter3D 的参数(与rgl 包中的plot3d 函数不同)。您也可以使用它:

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

    【讨论】:

    • 如果是连续图例呢?
    猜你喜欢
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多