简体   繁体   中英

Colors in plotly bar graph R

See also Custom colors in R Plotly

When using a variable for color in a plotly bar graph. How do you change the default color scheme?

    library(plotly)
    library(dplyr)

p <- ggplot2::diamonds %>% count(cut, clarity) %>%
  plot_ly(x = ~cut, y = ~n, color = ~clarity) %>%
  layout(barmode = "stack") 

p

在此处输入图片说明

colors argument of plot_ly takes a vector of length numbers of categories:

p <- ggplot2::diamonds %>% count(cut, clarity) %>%
   plot_ly(x = ~cut, y = ~n, color = ~clarity, colors = rainbow(10)) %>%
   layout(barmode = "stack") 
p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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