Andrew Tilley
Andrew Tilley

Reputation: 11

geom_point adds extra point at y max

Creating a box plot in R using ggboxplot. Using geom_point to add individual data points and position = position_jitter(width = 0.2)) to spread them out.

The generated plot consistently adds an extra point at y max (see image). So if n = 12, there are 13 points. I can't find any reason for this to be occurring. Code below:

enter image description here

plot <- ggboxplot(data, x = "treatment", y = "value", fill = "treatment", width = 0.4) + stat_summary(fun="mean", geom="point", shape=23, size=3, fill="white", position = position_dodge(width     = 0.7)) +
  geom_point(data = data, aes(x = treatment, y = value),
             position = position_jitter(width = 0.2)) +
  labs(x = "Treatment", y = "Concentration") +
  guides(fill = "none") +
  scale_fill_manual(values = cb_palette) +
  scale_y_continuous(breaks = c(5,10,15,20,25,30,35), limits = c(5,32)) +
  theme_bw(base_size = 18) +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.minor.y = element_blank()
        )

plot

Example dataset

sample  treatment   value
1   1   12.15980346
1   2   10.97915135
1   3   10.24602834
1   4   12.00826926
2   1   10.53893152
2   2   9.62200229
2   3   8.661327288
2   4   9.47010368
3   1   7.980431308
3   2   8.299834385
3   3   6.167766975
3   4   8.725891659
4   1   10.95137118
4   2   12.79031335
4   3   10.4178423
4   4   11.20135523
5   1   11.60301628
5   2   13.78625968
5   3   13.61339271
5   4   12.8500865
6   1   8.806134878
6   2   9.18175894
6   3   9.95901536
6   4   8.878521261
7   1   11.56143798
7   2   11.14678642
7   3   15.99024738
7   4   14.47572695
8   1   16.72820906
8   2   15.91346874
8   3   16.18871308
8   4   14.47575009
9   1   16.23862546
9   2   14.78037788
9   3   15.10731239
9   4   14.96026006
10  1   9.84265316
10  2   12.25204501
10  3   9.44290475
10  4   11.78481592
11  1   17.9120574
11  2   15.3130744
11  3   16.49442194
11  4   18.19518935
12  1   24.84358568
12  2   26.38818249
12  3   30.31382726
12  4   21.29795724

Any help would be greatly appreciated!

I have tried:

Upvotes: 1

Views: 41

Answers (0)

Related Questions