colorscale 不会改变 R 中 plotly 3d 散点图中的散点颜色
colorscale does not change the scatter points color in plotly 3d scatterplot in R
我正在学习使用 plotly 包在 r 中绘图。这段代码在 plotly 网站上提供:enter link description here。我将 colorscale = c('#FFE1A1', '#683531')
更改为 colorscale = c('blue', 'red')
。它不应该改变散点颜色吗?然后代码的哪一部分应该渐变地改变点的颜色。我知道我可以将它设置为调色板名称或类似“绿色”,但我不知道如何在两者之间提供一系列渐变颜色。
据我所知,3d 点不能有球体效果。只是想知道我是否可以将它与拥有的 rgl 包混合使用。
图书馆(剧情)
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
我正在学习使用 plotly 包在 r 中绘图。这段代码在 plotly 网站上提供:enter link description here。我将 colorscale = c('#FFE1A1', '#683531')
更改为 colorscale = c('blue', 'red')
。它不应该改变散点颜色吗?然后代码的哪一部分应该渐变地改变点的颜色。我知道我可以将它设置为调色板名称或类似“绿色”,但我不知道如何在两者之间提供一系列渐变颜色。
据我所知,3d 点不能有球体效果。只是想知道我是否可以将它与拥有的 rgl 包混合使用。
图书馆(剧情)
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