1

I'm trying to add means to a boxplot with points(). The code is working fine, I don't get any errors but the points won't appear.

This is my Code:

mean(BN$BN1, na.rm=T)
mean(BN$BN2, na.rm=T)

lillie.test(BN$BN_1)
lillie.test(BN$BN_2)

boxplot(BN$BN_1, BN$BN2, 
        main="Lilliefors-Test", xlab="BL 1", ylab="ART",
        varwidth=TRUE, col="darkseagreen", border="forestgreen")

points(1,mean(BN$BN_1), col="red")
points(2,mean(BN$BN_2), col="red")

my data looks like this:

'data.frame':   41 obs. of  3 variables:
 $ Art            : Factor w/ 41 levels "Achillea ptarmica",..: 13 8 9 14 19 20 28 12 1 3 ...
 $ BN_1: num  3 2 NA NA 2 2 2 2 2 2 ...
 $ BN_2: num  NA NA 3 2 3 3 3 2 2 2 …

Does anyone have an idea why it doesn't work? The same code works perfectly on similar data I have (with same conditions).

Thankful for any help!

dput

> dput(BN)
structure(list(Art = structure(c(13L, 8L, 9L, 14L, 19L, 20L, 
28L, 12L, 1L, 3L, 15L, 31L, 5L, 16L, 22L, 26L, 32L, 18L, 34L, 
10L, 2L, 21L, 37L, 35L, 30L, 27L, 24L, 41L, 4L, 33L, 17L, 39L, 
11L, 36L, 6L, 23L, 25L, 40L, 38L, 29L, 7L), .Label = c("Achillea millefolium KS_O", 
"Achillea millefolium KS_U", "Alopecurus pratensis", "Barbara vulgaris", 
"Brachypodium sylvestris", "Brassica napus", "Campanula rotundifolia", 
"Centaurea cyanus ", "Centaurea jacea ", "Cirsium arvense KS_O", 
"Cirsium arvense KS_U", "Dactylis glomerata", "Echium vulgare ", 
"Equisetum arvense ", "Galium mollugo", "Gaudinia fragilis", 
"Geranium pusillum", "Hypercium perforatum", "Leucanthemum ircutianum", 
"Lolium perenne", "Lotus corniculatis", "Malva sylvestris KS_O", 
"Malva sylvestris KS_U", "Medicago lupulina", "Mysotis sylvatica", 
"Papaver dubium", "Plantago lanceolata", "Poa pratensis", "Ranunculus abortivus", 
"Ranunculus repens", "Rumex crispus", "Silene dioica", "Silene latifolia", 
"Tanacetum vulgare", "Taraxacum officinale", "Tragopogon pratensis", 
"Trifolium pratense", "Veronica arvensis", "Vicia sativa", "Vicia tenuifolia ", 
"Viola arvensis"), class = "factor"), Bluehstreifen_1 = c(3, 
2, NA, NA, 2, 2, 2, 2, 2, 2, 2, 1, 1, NA, 1, 0.5, 0.5, 0.5, NA, 
NA, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, NA, 
NA, NA, NA, NA, NA), Bluehstreifen_2 = c(NA, NA, 3, 2, 3, 3, 
3, 2, 2, 2, 2, 0.5, 1, 1, NA, NA, NA, NA, 0.5, 0.5, 3, 3, 1, 
1, 1, 1, 1, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 0.5, 0.5, 0.5, 
0.5, 0.5)), class = "data.frame", row.names = c(NA, -41L))
jchm
  • 17
  • 5
  • Per `r` tag (hover or click to see): Please provide [minimal and reproducible example(s)](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5965451) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. – Parfait Oct 28 '19 at 19:06
  • I added the dput(). With library() I almost get two pages, not sure if this is right? – jchm Oct 28 '19 at 20:32
  • You have to add the `library` calls not run that empty line. What package does `lillie.test` derive? – Parfait Oct 28 '19 at 20:39
  • I only used package 'nortest' – jchm Oct 28 '19 at 20:50

1 Answers1

0

in the BN dataframe, the columns are named Bluehstreifen_1 and Bluehstreifen_2, and i am guessing that's BN_1 and BN_2. These columns have NAs, so when you do mean on a column containing NA, it returns NA. Do the following:

boxplot(BN$Bluehstreifen_1, BN$Bluehstreifen_2, 
        main="Lilliefors-Test", xlab="BL 1", ylab="ART",
        varwidth=TRUE, col="darkseagreen", border="forestgreen")

points(1,mean(BN$Bluehstreifen_1,na.rm=T), col="red")
points(2,mean(BN$Bluehstreifen_2,na.rm=T), col="red")

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72