0

I am trying to recreate this plot:

enter image description here

I have data on actual habitat presence and random data on expected habitat presence for 8 years. I want to see if the presence of bird species depends on the presence of certain crop types.

The code for the plot looks like this:

ggplot() + 
  geom_boxplot (data = random_soort2, aes(x=categorie, y=fractie, fill=type)) +
  theme_classic() +
  scale_fill_grey() +
  geom_point (data = sum_echt, aes(x=categorie, y = mean, fill=type),colour="red")

And creates the following plot:

enter image description here

The problem is that the red dots of the actual data are not separated by type, but are all grouped together. How do I separate them based on type?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Roos
  • 31
  • 2
  • 2
    You should provide some reproducible example. My guess is that you should use `color=type` instead of `fill=type` and remove the argument `color = red` outside the parenthesis. Type should probably be a factor column – Gerald T May 23 '23 at 10:43
  • 1
    Most likely issue is that `geom_point` uses `position="identity"` by default. To align the points with dodged box plots try `position = position_dodge(width = .75)`. See e.g. https://stackoverflow.com/questions/71287108/r-ggplot-geom-points-not-aligned-with-boxplot-bins – stefan May 23 '23 at 10:45
  • check also the ggbeeswarm package – Roman May 23 '23 at 12:07

0 Answers0