0

Using GGplot2 to create the following plot

plot1 <- ggplot(data=emodata, aes(x=trueSNR, y=score, colour=factor(Task)))
plot1 + stat_smooth(method="lm")+ facet_grid(. ~ Condition_f)

enter image description here

I'm trying to change the default axes names (y = "score" to be "proportion correct", x="trueSNR" to be "dB SNR"). By default they get the variable name in the dataframe. This seems like something that should be really easy, but I can't find a question here that answers it (most seem like they discuss re-labelling the axis, which seems problematic when using facet_grid). The primary issue is trying to edit axis labels from within the facet_grid arguments.

Anyway, I know this may be trivial, but I'd appreciate any help!

shaedopotato
  • 457
  • 1
  • 3
  • 12
  • See the `labs()` or `ylab()` function – Dave2e Mar 17 '23 at 13:38
  • @benson23 yes, that answers it - the solutions here feel more clear to me so I'd like to keep this a separate question. I updated the question to clarify that the question is whetehr or not you can change axis labels using the facet_grid function, which it appears you cannot. – shaedopotato Mar 18 '23 at 14:43

2 Answers2

2

You can change the axes names similar to any other ggplot plot. One way of doing this is with the labs function:

plot1 + labs(x = "proportion correct", y = "dB SNR")

The labs can be added before or after the facet_grid and both work. Hope this helps!

Tyler
  • 336
  • 1
  • 7
1

Try using labs():

plot1 + stat_smooth(method="lm")+ facet_grid(. ~ Condition_f) +
 labs(x="trueSNR", y="proportion correct")
S-SHAAF
  • 1,863
  • 2
  • 5
  • 14