0

I just asked this question: R - Plotting 4 variables at once with ggplot2

The answer helped me a lot, but the result on my real data is not ideal. I would like to stay with only one shape only and color this one in 2 colors.

I found this question: Plot border and fill in a *single* shape? This is exactly what I want, but I cant get it working on my data.

This is what I have tried:

ggplot(df, aes(Code, Corr)) + 
  geom_point(aes(colour Vari, 
                 fill = Con), shape=21, size = 4) + 
  scale_fill_manual(values=c("yellow", "black", "grey", "purple", "plum", "cyan", "dimgrey")) + 
  scale_colour_manual(values=c("red", "dodgerblue", "seagreen", "orange", "deeppink", "saddlebrown"))

And here is my dataframe sample:

df <- structure(list(Vari = c(
  "PM", "TMK", "VPM",
  "TMK", "TXK", "TNK", "TGK", "VPM", "TMK",
  "TXK", "TNK", "TGK", "VPM", "TMK", "VPM",
  "TMK", "TNK", "TGK", "VPM", "TMK", "TXK",
  "TNK", "TGK", "VPM", "TNK", "TGK", "VPM",
  "TMK", "TXK", "TNK", "TGK", "TNK", "TGK",
  "TMK", "TXK", "TNK", "TGK"
), Code = c(
  "R10",
  "J06", "J20-J22", "J20-J22", "J20-J22", "J20-J22", "J20-J22",
  "J20-J22", "J20-J22", "J20-J22", "J20-J22", "J20-J22", "J06",
  "J06", "J20", "J20", "J20", "J20", "J20-J22", "J20-J22", "J20-J22",
  "J20-J22", "J20-J22", "J20", "J20", "J20", "J20-J22", "J20-J22",
  "J20-J22", "J20-J22", "J20-J22", "H00-H06", "H00-H06", "B85-B89",
  "B85-B89", "I20-I25", "I20-I25"
), Corr = c(
  -0.569, -0.5125,
  -0.5739, -0.5843, -0.5603, -0.5744, -0.5547, -0.6168, -0.5897,
  -0.5458, -0.5867, -0.5628, -0.5047, -0.5086, -0.5172, -0.512,
  -0.5229, -0.5257, -0.6172, -0.6003, -0.5599, -0.602, -0.5912,
  -0.5032, -0.5121, -0.5187, -0.5966, -0.59, -0.5661, -0.5879,
  -0.5589, 0.5104, 0.5758, 0.5491, 0.528, -0.5153, -0.5516
), Con = c(
  "Hi",
  "Eg", "Eg", "Eg", "Eg", "Eg", "Eg", "WFX",
  "WFX", "WFX", "WFX", "WFX", "WFM",
  "WFM", "WFM", "WFM", "WFM", "WFM",
  "WFM", "WFM", "WFM", "WFM", "WFM",
  "No2", "No2", "No2", "No2", "No2", "No2",
  "No2", "No2", "PM25", "PM25", "MAM", "MAM",
  "Hi", "Hi"
)), row.names = c(
  23L, 35L, 36L, 37L, 38L,
  39L, 40L, 43L, 44L, 45L, 46L, 47L, 50L, 51L, 52L, 53L, 54L, 55L,
  58L, 59L, 60L, 61L, 62L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
  74L, 75L, 86L, 87L, 100L, 101L
), class = "data.frame")
Mr.Spock
  • 511
  • 2
  • 13
  • there is a `=` missing in your example, at `geom_point(aes(colour Vari`, which should be `geom_point(aes(colour=Vari,` Is that already the error your facing? – NicolasH2 Apr 20 '21 at 12:19
  • Oh gosh, thanks! I get a plot now, but also a warning message: In doTryCatch(return(expr), name, parentenv, handler) : display list redraw incomplete – Mr.Spock Apr 20 '21 at 14:03
  • mh, with the dataframe you provided I do not get this error message. Works like a charm for me. Maybe that's more of an RStudio error(?), see https://community.rstudio.com/t/strange-warning-on-initial-rstudio-statement/57003. Did you try restarting Rstudio, so everyhting is fresh and you only use exactly the code and data.frame that you posted? – NicolasH2 Apr 20 '21 at 15:04
  • Thank you! I got it now. My problem is the overlapping. Do you know how to line up the circles, so put them next to each other within their group and not all at the same spot. – Mr.Spock Apr 22 '21 at 17:02
  • you can replace `geom_point` with `geom_jitter` or you can use the ggbeeswarm package and use `geom_beeswarm` instead (looks often nicer) – NicolasH2 Apr 22 '21 at 18:08

0 Answers0