Ali*_*aib 5 plot r bar-chart ggplot2 geom-bar
我有这个数据:
table(main$Sex1,main$District)
Bahawalnagar Barkhan Chiniot Faisalabad Ghotki
Female 37 16 26 97 46
Male 25 19 15 20 25
Run Code Online (Sandbox Code Playgroud)
我可以用基础 R 绘制它
barplot(table(main$Sex1,main$District))
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我怎样才能用 ggplot2 做到这一点?谢谢
ggplot(as.data.frame(table(main$Sex1,main$District)), aes(Var1, Freq, fill=Var2)) +
geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud)
table 类很长,但它以特殊方式打印,ggplot 不知道如何处理它。如果你用 as.data.frame 传递它,那么 ggplot 就可以完美地管理它。
| 归档时间: |
|
| 查看次数: |
2327 次 |
| 最近记录: |