I would like to have two bar charts on the same plot.
Let's say these two bar charts will be based on a variable Var1
with two levels ( Var1
is a column in the table). I have the frequencies in the same table where x
represents the counts and y
represents different levels of interest. If I use the below code, then I get them on the same plot but it shows the results for two levels of Var1
on the same bar for a level of y
. I would like to have two bars side by side representing two levels of Var1
for a level of y
. How do I do that? Thanks!
ggplot(data,aes(x,y,fill=Var1)) + geom_bar(stat="identity")
在geom_bar
添加position = "dodge"
:
ggplot(data,aes(x,y,fill=Var1)) + geom_bar(stat="identity", position = "dodge")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.