0

I have the following dataframe

View(d.df)
Statements | Score | Time
-----------+-------+------
Need Ex    |4.159  | T1
Need Ex    |3.714  | T2
Interest   |2.937  | T1
Interest   |3.508  | T2

and my plot

ggplot(data=d.df, aes(x=`Time`,y=Score, fill=`Time`)) +
  geom_bar(stat="identity") +
  scale_fill_manual(values=c("red","blue"))+
  facet_wrap(~Statements)

Produces the right graph, but the Y axis scale does not start in zero. I want the Y axis to go from zero to 4.5. I tried adding

+ scale_y_continuous(limits=c(0.0,4.5))

but I get an error saying:

Error: Discrete value supplied to continuous scale

If I try

+ coord_cartesian(ylim=c(0,4.5))

the coordinates stay pretty much the same (adds a bit of padding at the bottom). Any ideas on how to get my axis to go proportionally from 0 to 4.5 with this data?

fiacobelli
  • 1,960
  • 5
  • 24
  • 31

1 Answers1

1

I can't reproduce your example, as the Y starts at 0 here.

My best guess is that your Score column is not numeric but a factor (this is what the error states).

Try to change this column to numeric with d.df %>% mutate(Score = as.numeric(Score)) before plotting.

Colin FAY
  • 4,849
  • 1
  • 12
  • 29