0

First thing I'd love your help with is how to change the default jitter colors - would love for Cold to be blue as it is, Average black, and High red. Couldn't find a proper line of code to do that.

Also, I'd love to add a smooth line to connect the jitter for each "type" (Low/Average/High), same color as specific jitter. In total 3 lines. I've tried geom_smooth and geom_line and both have failed me.Does anyone have an idea?

OK, so my code looks like this:

myplot <- ggplot(longdata, aes(x = Month, y = temp)) +
  scale_x_discrete(limits = c("January", "February", "March", "April",
                              "May", "June", "July", "August", "September", 
                              "October", "November", "December")) +
  scale_y_discrete(limits=c(0, 5, 10, 15, 20, 25, 30)) + 
  geom_jitter(aes(colour = type))

Which gives me this plot:

scatterplot

kjetil b halvorsen
  • 1,206
  • 2
  • 18
  • 28
  • Try `scale_color_manual(values = c(Low = "blue", Average = "black", High = "red"))` for the colors. See e.g. https://stackoverflow.com/questions/43770579/how-to-change-the-color-in-geom-point-or-lines-in-ggplot – stefan Feb 22 '23 at 15:56

1 Answers1

0

You can add a manual scale for the color aesthetic as described in the documentation.

In regards to your question about adding a line, I suspect your issue is due to the fact that you are not grouping by type globally. If you set color = type to be a parameter for the entire ggplot, all geom_* functions will adhere to those aesthetics (as explained more in this question).

This code should solve both issues:

myplot <- ggplot(longdata, aes(x = Month, y = temp, color = type)) +
  scale_x_discrete(limits = c("January", "February", "March", "April",
                            "May", "June", "July", "August", "September", 
                            "October", "November", "December")) +
  scale_y_discrete(limits=c(0, 5, 10, 15, 20, 25, 30)) + 
  geom_jitter() +
  geom_line() +
  scale_color_manual(values = c(Low = "blue",
                                Average = "black",
                                High = "red"))
mfg3z0
  • 561
  • 16