簡體   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