我有以下数据集:
sector <- c("Basic Materials", "Communication Services", "Consumer Cyclical", "Basic Materials", "Communication Services", "Consumer Cyclical")
variable_set <- c("average ROE", "average ROE","average ROE","CAGR ROE","CAGR ROE","CAGR ROE")
value <-c(-3,7,5,4,3,2)
data <- cbind(sector, variable_set, value)
我的目标是创建一个条形图,x 轴按部门分组,y 轴 1 = 平均 ROE,y 轴 2 = CAGR ROE。我希望 ROE 和 CAGR 的条形按部门分组,即彼此相邻。
我的尝试:
ggplot(data, aes(x = variable_set, y = value, fill = factor(sector))) + geom_bar(stat = "identity",position="dodge") +
theme(text = element_text(size = 12), axis.text.x = element_text(angle=90, vjust=0.5, hjust = 1))