1

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")
1
  • 1
    actual data would be rly helpful to those you're seeking help from Commented Sep 14, 2015 at 17:33

1 Answer 1

1

Add position = "dodge" to the geom_bar:

ggplot(data,aes(x,y,fill=Var1)) + geom_bar(stat="identity", position = "dodge")
Sign up to request clarification or add additional context in comments.

1 Comment

Great! Thanks. This was what I needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.