我正在尝试通过points()将均值添加到箱线图中。 代码工作正常,我没有收到任何错误,但这些要点不会出现。
这是我的代码:
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")
我的数据如下:
'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 …
有人知道为什么它不起作用吗? 相同的代码可以完美地处理我拥有的相似数据(条件相同)。
感谢您的帮助!
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))
答案 0 :(得分:0)
在BN数据框中,这些列分别命名为Bluehstreifen_1和Bluehstreifen_2,我猜是BN_1和BN_2。这些列具有NA,因此当您对包含NA的列进行平均时,它将返回NA。请执行以下操作:
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")