R Plot_ly:如何更改颜色栏的调色板和色阈值?

时间:2020-04-18 15:15:40

标签: r plotly pca

我正在尝试绘制3D散点图(前3个维度的PCA散点图),但是我找不到在plot_ly上更改颜色条的方法。

下面是代码,这是我获得的代码,但我希望它从红色(大多数负值)变为绿色(较高值),并且转折点(淡粉色)的值为0,而不是+18 ‰似乎在图表上。

你能帮我吗?

enter image description here

ind5<-get_pca_ind(PCA_data5)
a<-ind5$coord[,1]
b<-ind5$coord[,2]
c<-ind5$coord[,3]
d<-Interviews$`Annual_SOC_rate_‰`

f1 <- list(
  family = "Times New Roman",
  size = 20,
  color = "black")


fig <- plot_ly(Interviews, x = ~a, y = ~b, z = ~c,
               marker = list(color = ~d,
                             colorbar=list(tickfont=f1),
                             showscale = TRUE))
fig <- fig %>% add_markers()
fig <- fig %>% layout(scene = list(xaxis = list(title = 'Dim1 (18.8%)',
                                                titlefont = f1,
                                                tickfont = f1),
                                   yaxis = list(title = 'Dim2 (16.3%)',
                                                titlefont = f1,
                                                tickfont = f1),
                                   zaxis = list(title = 'Dim3 (13.2%)',
                                                titlefont = f1,
                                                tickfont = f1)),
                      annotations = list(
                        x = 1.13,
                        y = 1.05,
                        text = 'Annual SOC change rate (‰)',
                        font=f1,
                        xref = 'paper',
                        yref = 'paper',
                        showarrow = FALSE
                      ))
fig

1 个答案:

答案 0 :(得分:1)

改为尝试

<h1><fa-icon [icon]="['fas','images']"></fa-icon> Images</h1>

或这个

fig <- plot_ly(Interviews, x = ~a, y = ~b, z = ~c,
               marker = list(color = ~d,
                             colorbar=list(tickfont=f1),
                             colorscale = list(c(0,'red'),
                                               c(0.5,'pink'),
                                               c(1, 'green'))))