我需要做这个情节
我的理解是,我需要对模型名称name
(base与mother)使用fill,对Year使用group。
我试过了
test%>%ggplot(aes(as_factor(sector), value, fill=name, group=factor(YEAR)))+
geom_col(position = "dodge", width=0.5)
但它不起作用...
如何解决这个问题?:(
我的数据如下所示
structure(list(value = c(45.7835023085923, 46.727175387221, 47.6992761579977,
48.0597275867616, 50.7882757046681, 50.8768402521772, 42.7273124207896,
43.9851413648616, 47.5599896653421, 47.8361505231604, 51.0693121296854,
51.2675797116211, 45.0282059530599, 46.0840505213407), name = c("value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total", "value_add_base_sector_total",
"value_add_mother_sector_total"), YEAR = c(2011, 2011,
2011, 2011, 2011, 2011, 2016, 2016, 2016, 2016, 2016, 2016, 2021,
2021), sector = c("Catholic", "Catholic", "Government", "Government",
"Independent", "Independent", "Catholic", "Catholic", "Government",
"Government", "Independent", "Independent", "Catholic", "Catholic"
)), row.names = c(NA, -14L), class = c("tbl_df", "tbl", "data.frame"
3条答案
按热度按时间4ngedf3f1#
像这样?
ulydmbyx2#
你可以
owfi6suc3#
我同意刻面在这里可能是有用的,除非,你需要它看起来完全一样(没有刻面?)。否则我会使用facet.grid并将条带移动到图表的底部。我添加了一个负值,使它看起来更相似,你可以玩主题来更改样式...
添加负值并更改“名称”
图
enter image description here