I've got this data:
table(main$Sex1,main$District)
Bahawalnagar Barkhan Chiniot Faisalabad Ghotki
Female 37 16 26 97 46
Male 25 19 15 20 25
I can plot it with base R
barplot(table(main$Sex1,main$District))
So my question is, how can I do this with ggplot2? Thanks
ggplot(as.data.frame(table(main$Sex1,main$District)), aes(Var1, Freq, fill=Var2)) +
geom_bar(stat="identity")
table class is long, but it prints in a special way, and ggplot doesn't know how to handle it. If you pass it with as.data.frame it will be perfectly manageable by ggplot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With