简体   繁体   English

设置子图颜色绘图 R

[英]Set subplot colors plotly R

I have this code for subplots, i want to set de colors by a custom palette, but seems not to take any color.我有这个子图的代码,我想通过自定义调色板设置颜色,但似乎不采用任何颜色。

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)

One option to achieve your desired result would be to map the grouping variable on the color "aesthetic" and to set the custom palette via the colors argument where personally I prefer to make use of a named vector to assign colors to categories:实现您想要的结果的一种选择是将分组变量映射到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
  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM