0

I am trying to create a scatterplot with pesticide concentrations from week 1 on the x axis and from week 2 on the y axis. I would like to make those who live near an agricultural field one color filled in, and those who live far from an agricultural field another color with a hollow symbol. I would also like to make those who did not follow the intervention to be a different symbol (such as a triangle).

I have figured out how to change the color for near/far field and how to change the symbol based on those who didn't follow the intervention, but cannot for the life of me figure out how to change the fill for the near-field participants.

I have tried various iterations with both geom_point and scale_shape_manual and can't get it to work. Here is some of the code I have tried:

    geom_point(aes(shape=exclusion, fill=Field), size=3) +
      scale_x_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      scale_y_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
        limits = c(NA, 1.2)) +
      guides(colour = guide_legend(title="Residenital Proximity\nto 
        Agricultural Field")) + 
      scale_color_discrete(labels = c("Far Field", "Near Field")) + 
      labs(y="Urinary glyphosate concentration (ug/L) conventional 
        week", x="Urinary glyphosate (ug/L) organic week"
      geom_abline(slope=1, intercept=0) +
        theme_minimal() + 
        theme(strip.text = element_blank (),
           legend.title = element_blank(),
           legend.position = "none")  

I have also tried:

    ggplot(data=data_scatter, aes(x=result_org, y=result_conv)) + 
      geom_point(aes(color=factor(Field), 
                     shape=factor(excl_3))) + 
      scale_shape_manual(values=c(1, 2, 16, 17)) + 
      scale_x_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      scale_y_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      guides(colour = guide_legend(title="Residenital Proximity\nto 
        Agricultural Field")) + 
      labs(y="Urinary glyphosate concentration (ug/L) conventional 
        week", x="Urinary glyphosate concentration (ug/L) organic 
        week") +
      geom_abline(slope=1, intercept=0) +
      theme_minimal() 

When I do this, I get the following image, where I have the difference in color/shape, but not fill 1

  • 1
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data so that others can run your code. – stefan May 15 '23 at 20:32
  • Only shapes 21-25 are eligible for different color and fill values. When you set your shape values to `values=c(1, 2, 16, 17)`, you are selecting shapes that cannot be filled. See the shapes at `?pch`, the ones that have a gray fill and black outline are the ones that can be colored and filled independently. – Gregor Thomas May 15 '23 at 20:46
  • OP, what does the structure of your data look like? In particular, does the `Field` column contain number/values which correspond to "Near Field", "Far Field", and "didn't follow directions" or whatever your third option was? – chemdork123 May 15 '23 at 20:50

0 Answers0