0
ggplot(aushealth, aes(x=condition, y=Population, fill=year)) +
+ geom_bar(stat="identity", position=position_dodge())

Hoping to have the years side by side, but they appear on top of each other.

Condition     Year   Population
Asthma        2001   10.0
Asthma        2017   13.1
Back Issue    2001   7.5
Back Issue    2017   6.3

What am I doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Hi, please check a guide on how to ask good questions on stack overflow: https://stackoverflow.com/help/how-to-ask and how to make good reproducible examples in R: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example . It will help you get higher quality answers faster. – ira Sep 10 '18 at 10:24

1 Answers1

0

You had some errors in the code:

tt = "Condition Year Population
Asthma 2001 10.0
Asthma 2017 13.1
Back_Issue 2001 7.5
Back_Issue 2017 6.3"

dat <- read.table(text = tt, header = T)

ggplot(dat, aes(x=Condition, y=Population, fill=as.factor(Year))) + 
  geom_bar(stat="identity", position=position_dodge())

Condition wasn't with capital C, also use as.factor on Year. That was the main issue.

enter image description here

RLave
  • 8,144
  • 3
  • 21
  • 37