rggplot2

ggplot2 geom_jitter, colors


dotAW <- A_W_point
dotAW <- ggplot(dotAW,aes(x=AASW, y=WW, fill=taxa))  
dotAW <- dotAW  + geom_jitter(aes(color = taxa), size = 4)
dotAW <- dotAW  +geom_abline(intercept = 0, slope = 1)
dotAW <- dotAW + scale_y_continuous(limits=c(0,0.5)) + scale_x_continuous(limits=c(0,0.5))
dotAW

ggsave(dotAW, file="dotAW.pdf", width=12, height=10)

With this plot I want to correlate relative abundance of bacterial taxa. I have some issues to solve, where I need help

  1. I want to change the color with eg + scale_fill_hue(l=45) or by creating my own color vector, but I don't know where to place it in the script, the colors are defined somehow connected to geom_jitter. In the end I want for each taxa an individual combination of color and shape to distinguish them in the plot easier than only using color.
  2. I would like to define the dimension of the plot already before saving. Where and how can I add the height and width before?
  3. Is the use of geom_jitter correct? It's a bit tricky for me to understand what it does.

here is a link to the data: https://docs.google.com/spreadsheets/d/1w5gHoWjFsgUUXEZOv9PTKfRQ-GyMkqulpAFVJaiX1K8/edit?gid=0#gid=0


Solution

  • With geom_jitter the point are plotted in their exact location, but somewhat besides that (above/below and/or right/left).

    I've put your data in a dataframe df. Then you can create your plot with:

    dotAW <- ggplot(df,aes(x=AASW, y=WW, color=taxa)) + 
      geom_point(shape = 20, size = 4, position = "jitter") +
      geom_abline(intercept = 0, slope = 1) + 
      scale_y_continuous(limits=c(-0.05,0.5)) + 
      scale_x_continuous(limits=c(-0.05,0.5)) +
      scale_color_hue()
    dotAW
    

    which gives the following result:

    enter image description here

    You can set the colors manually with scale_color_manual() like this:

    scale_color_manual(values = c("Flavobacteriaceae"="red", "Oceanospirillales"="blue", "Gammaproteobacteria" = "green"))