我想使用geom_bar()函数创建一个并排的条形图,基于这个数据框:
> dfp1
value percent1 percent
1 (18,29] 0.20909091 0.4545455
2 (29,40] 0.23478261 0.5431034
3 (40,51] 0.15492958 0.3661972
4 (51,62] 0.10119048 0.1726190
5 (62,95] 0.05660377 0.1194969
将数值放在x轴上,将百分比作为并排柱状图。我尝试使用以下代码:
p = ggplot(dfp1, aes(x = value, y= c(percent, percent1)), xlab="Age Group")
p = p + geom_bar(stat="identity", width=.5)
然而,我遇到了这个错误:Error: Aesthetics must either be length one, or the same length as the dataProblems:value。我的percent和percent1与value的长度相同,所以我很困惑。感谢您的帮助。