繁体   English   中英

colorscale 不改变 plotly 中的散点颜色 3d 中的散点图 R

[英]colorscale does not change the scatter points color in plotly 3d scatterplot in R

我正在使用 plotly package 学习 r 中的 plot。这段代码在 plotly 网站上提供:在此处输入链接描述 我将colorscale = c('#FFE1A1', '#683531')更改为 colorscale colorscale = c('blue', 'red') 它不应该改变散点 colors 吗? 然后代码的哪一部分应该渐变地改变点的颜色。 我知道我可以将它设置为调色板名称或类似“绿色”,但我不知道如何在两者之间提供梯度范围 colors。


据我所知,plotly 3d 点不能有球体效果。 只是想知道我是否可以将它与 rgl package 混合使用。

图书馆(情节)

 fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, marker = list(color = ~mpg, colorscale = c('#FFE1A1', '#683531'), showscale = TRUE)) fig <- fig %>% add_markers() fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'), yaxis = list(title = 'Gross horsepower'), zaxis = list(title = '1/4 mile time')), annotations = list( x = 1.13, y = 1.05, text = 'Miles/(US) gallon', xref = 'paper', yref = 'paper', showarrow = FALSE )) fig

我今天遇到了完全相同的问题,您可以在使用色标之前将比例创建到列表中:

colorscale <- list(c(0, 1), c("blue", "red"))
# or
colorscale <- list(c(0, 1), c("#FFE1A1", "#683531"))

完整代码

fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec,
               marker = list(color = ~mpg, colorscale=list(c(0, 1), c("blue", "red")), showscale = TRUE))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'),
                                   yaxis = list(title = 'Gross horsepower'),
                                   zaxis = list(title = '1/4 mile time')),
                      annotations = list(
                        x = 1.13,
                        y = 1.05,
                        text = 'Miles/(US) gallon',
                        xref = 'paper',
                        yref = 'paper',
                        showarrow = FALSE
                      ))
fig

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM