【问题标题】:Set subplot colors plotly R设置子图颜色 plotly R
【发布时间】:2021-12-26 20:56:53
【问题描述】:

我有这个子图代码,我想通过自定义调色板设置颜色,但似乎没有任何颜色。

data.frame(x = sample(letters[1:3],30,replace = TRUE)) %>%
  mutate(y = rnorm(30),
         z = runif(30,10,20)) %>%
  group_by(x) %>%
  do(p=plot_ly(.,x = ~y, y=~z, type = "scatter", mode = "lines", line = list(color = "blue","red","green")))) %>%
  subplot(nrows = 1,
                  shareX = FALSE,
                  shareY = TRUE,
                  margin = 0.0001)

【问题讨论】:

    标签: r dplyr plotly data-visualization


    【解决方案1】:

    实现所需结果的一个选项是将分组变量映射到color“审美”并通过colors 参数设置自定义调色板,我个人更喜欢使用命名向量来分配颜色分类:

    library(plotly)
    
    set.seed(123)
    
    data.frame(x = sample(letters[1:3], 30, replace = TRUE)) %>%
      mutate(
        y = rnorm(30),
        z = runif(30, 10, 20)
      ) %>%
      group_by(x) %>%
      do(p = plot_ly(., x = ~y, y = ~z, color = ~x, type = "scatter", mode = "lines", colors = c(a = "blue", b = "red", c = "green"))) %>%
      subplot(
        nrows = 1,
        shareX = FALSE,
        shareY = TRUE,
        margin = 0.0001
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2020-12-04
      • 2020-03-13
      • 2020-10-06
      • 2021-02-22
      • 1970-01-01
      相关资源
      最近更新 更多