[英]ggplot2: geom_bar fill colour; how to change to different grouping of data
我有以下数据集,显示了会计期间,产品和交易总额:
app$FISCAL_PERIOD <-c(201604,201604,201604,201605,201605,201605,201606,201606,201606,201607,201607,201607,201608,201608,201608,201609,201609,201610,201610,201611,201611)
app$Product <- c("Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 1","Product 3","Other","Product 2","Product 3","Product 2","Product 3","Product 2","Product 3")
app$sum_trans<-c(78,23410,1946,84,29532,417,16,30364,129,305,32386,584,424,20873,274,20,20929,470,19261,10,6131)
我在ggplot2中将其绘制为躲避的条形图。 Ggplot会自动为每个填充分配颜色,以便每个会计期间使用不同的颜色。
ggplot(data = app, aes(x = Product, y = sum_trans, fill = as.factor(FISCAL_PERIOD))) +
geom_bar(stat="identity", position="dodge", colour="black")
我需要显示每种具有相同颜色和不影响图表的填充变量的产品。 即我希望所有产品1会计期间数据为一种颜色,而所有产品3会计期间数据为另一种颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.