简体   繁体   English

如何在R中使用plotly更改条形图中的配色方案?

[英]How to change color schemes in bar graphs using plotly for R?

I want to use a different color scheme for my bar graph using the plotly library, its code is looking like this right now: 我想使用plotly库为条形图使用其他颜色方案,它的代码现在看起来像这样:

library(plotly)

p <- plot_ly(
 x=c("1","2", "3", "4", "5", "6", "7", "8", "9"),
 y=c(0.79, 0.57, 0.57, 0.59, 0.46, 0.38, 0.33, 0.57),
 name = "2007",
 type = "bar"
)
p

p2 <- add_trace(
  p,
  x=c("1","2", "3", "4", "5", "6", "7", "8", "9"),
  y=c(0.79, 0.57, 0.57, 0.59, 0.46, 0.38, 0.25, 0.58),
  name = "2008",
  type = "bar")
p2

Do you mean something like this: 您的意思是这样的吗:

p <- plot_ly(
 x=c("1","2", "3", "4", "5", "6", "7", "8", "9"),
 y=c(0.79, 0.57, 0.57, 0.59, 0.46, 0.38, 0.33, 0.57),
 name = "2007",
 type = "bar", marker = list(color = toRGB("yellow"))
)
p

p2 <- add_trace(
  p,
  x=c("1","2", "3", "4", "5", "6", "7", "8", "9"),
  y=c(0.79, 0.57, 0.57, 0.59, 0.46, 0.38, 0.25, 0.58),
  name = "2008",
  type = "bar", marker = list(color = toRGB("black")))
p2

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

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