[英]colorscale does not change the scatter points color in plotly 3d scatterplot in R
I am learning to plot in r using plotly package. This chunk of code is provided on plotly website: enter link description here .我正在使用 plotly package 学习 r 中的 plot。这段代码在 plotly 网站上提供:在此处输入链接描述。 I change colorscale = c('#FFE1A1', '#683531')
to let say colorscale = c('blue', 'red')
.我将colorscale = c('#FFE1A1', '#683531')
更改为 colorscale colorscale = c('blue', 'red')
。 shouldnt it change the scatter points colors?它不应该改变散点 colors 吗? what part of the code is then supposed to change the color of the points gradiently.然后代码的哪一部分应该渐变地改变点的颜色。 I know I can set it to pallette names or like "Greens", but I dont know how to give a range of gradient colors between two.我知道我可以将它设置为调色板名称或类似“绿色”,但我不知道如何在两者之间提供梯度范围 colors。
library(plotly)图书馆(情节)
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
I had the exact same issue today, you can create your scale into a list before using colorscale:我今天遇到了完全相同的问题,您可以在使用色标之前将比例创建到列表中:
colorscale <- list(c(0, 1), c("blue", "red"))
# or
colorscale <- list(c(0, 1), c("#FFE1A1", "#683531"))
Full code完整代码
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.