[英]plot 2 x variables R plotly barchart
也许尝试像下面这样?
df = data.frame(
Year=rep(1999:2019,2),
Percent=rpois(42,4),
Sex=rep(c("Men","Women"),each=21))
library(plotly)
COLS = c("#ffd369","#015668")
df$Year = factor(df$Year)
并排:
p = plot_ly(df,x=~Year,y=~Percent,name=~Sex,type='bar',colors=COLS,color=~Sex) %>%
layout(xaxis = list(title =NA),
legend = list(orientation = "h",xanchor = "center",x=0.5)
)
堆叠:
p %>% layout(barmode = 'stack')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.