0
votes

I am plotting three years of data on a scatterplot in ggplot2, with years as the y-axis. The axis is scaling so that the tick mark labels are "2015.5, 2016, 2016.5 … etc." and I need them to just be "2016 2017 2018". I have tried to use the scale_y_discrete function.

Here is my code

x <- (plot <- ggplot(NULL, aes(sos, year)) + 
  geom_jitter(data = epic, aes(col = "EPIC")) +
  geom_jitter(data = landsat, aes(col = "Landsat")) +
  geom_jitter(data = pheno, aes(col = "PhenoCam")))
x + labs(title = "Start of Season Comparison",
       x = "DOY",
       y = "Year")

and here is the current scatterplot

Thank you!

2
What did ggplot say or do when you used scale_y_discrete?Edward
you could try using scale_y_continuous and setting the breaks argumentJonathan V. Solórzano
@Edward when I use scale_y_discrete it removes the y-label entirely. I added this code to the end of the script above scale_y_discrete(breaks=c("2016", "2017", "2018"), labels=c("2016", "2017", "2018")) and also tried it without breaks.Maridee Weber
@JonathanV.Solórzano using scale_y_continuous and setting the breaks argument gives me the error: "Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : non-numeric argument to binary operator". Perhaps I am setting the breaks wrong? I am a new programmer...here is what I used scale_y_continuous(breaks=c("2016", "2017", "2018"))Maridee Weber
Try setting the breaks without the "" (quotes), like breaks = c(2016, 2017, 2018)Jonathan V. Solórzano

2 Answers

0
votes

Have you checked to see the year variable is numeric ? If that is numeric then I think Solorzanos solutions should work

0
votes

One easy way is to change year as factors, but I am not sure if this is correct way of doing it or not.

ggplot(NULL, aes(sos, as.factor(year))) +