1

I'm trying to add a grouped boxplot into a boxplot with only one group. I already made it, but the problem is that I can't give a name to the boxplot that has only one group. It is simply not shown. The arguments "name" and "names" don't seem to work when your boxplot does not have different groups.

boxplot(Daten$NV,
        boxwex = 0.6, at = 1:1 - 0.2,col = "yellow",
        name = "Gesamtstichprobe",
        main = "Guinea Pigs' Tooth Growth",
        xlab = "Vitamin C dose mg",
        ylab = "tooth length",
        xlim = c(0.5, 3.5), ylim = c(0, 7), yaxs = "i")
boxplot(Daten$NV ~ Daten$CVKGruppe, add = TRUE,
        boxwex = 0.3, at = 1:3 + 0.3, col = "orange")

Click here for Boxplot-Image

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
Drako
  • 13
  • 2
  • Hi, could you make this more [*reproducible*](https://stackoverflow.com/a/5963610/6574038)? – jay.sf Apr 26 '22 at 20:19
  • Please share your data using something like `dput(yourdata)` or a subset of your data (i.e. `dput(yourdata[1:100,])` – jpsmith Apr 26 '22 at 20:21

1 Answers1

0

You could do:

boxplot( Daten$NV,
        boxwex = 0.6, at = 1:1 - 0.2, col = "yellow",
        name = "Gesamtstichprobe",
        main = "Guinea Pigs' Tooth Growth",
        xlab = "Vitamin C dose mg",
        ylab = "tooth length",
        xlim = c(0.5, 3.5), ylim = c(0, 7), yaxs = "i", xaxt = "n")
axis(1, at = 0.8, labels = "Total")
boxplot(Daten$NV ~ Daten$CVKGruppe, add = TRUE,
        boxwex = 0.3, at = 1:3 + 0.3, col = "orange")

enter image description here

Created on 2022-04-26 by the reprex package (v2.0.1)


Data

set.seed(1)
Daten <- data.frame(NV = rnorm(150, 4, 1),
  CVKGruppe = rep(c("Kamera aus", "Kamera ein_VH an", "Kamera eien_VH aus"),
                  each = 50))

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87