[英]Add name to boxplot in R
這個問題與: R: how to label the x-axis of a boxplot
當繪制多於一列時,會出現名稱。 但是當只繪制一列時,名稱不會出現,即使使用 names=.. 參數:
ddf = structure(list(apple = c(1, 2, 3, 4, 5), banana = c(5, 4, 3,
2, 1), watermelon = c(4, 5, 6, 7, 8)), .Names = c("apple", "banana",
"watermelon"), row.names = c(NA, -5L), class = "data.frame")
ddf
apple banana watermelon
1 1 5 4
2 2 4 5
3 3 3 6
4 4 2 7
5 5 1 8
boxplot(ddf[,1:2])
boxplot(ddf[,1])
以下也不起作用:
boxplot(ddf[,1], names='apple')
boxplot(ddf[,1], names=c('apple'))
僅使用一列時,如何向箱線圖中添加名稱? 謝謝你的幫助。
有一個show.names=
參數bxp
,這boxplot
電話。 你可以這樣做:
boxplot(ddf[1], show.names=TRUE)
確保這是ddf[1]
而不是ddf[,1]
,以便保留名稱。
也許你可以使用“xlab”:
boxplot(ddf[,1], xlab="apple")
一種方法是使用mtext
:
boxplot(ddf[,1])
mtext("apple", side=1, line=1)
默認情況下,箱線圖在x=1
添加,因此您可以將刻度和軸標簽添加到x=1
就像繪制多列時一樣。
axis(side = 1, at = 1, labels = 'apple')
我還為show.names
{car} 使用了帶有show.names
的解決方案。 就我而言,我想在一個箱線圖中總結一些列並同時標記異常值,因此我使用了Boxplot
。
Boxplot(df, show.names = T, names = "test samples", labels = rownames(df), id.method = c("y"), id.n=9)
對於boxplot
,如果您對數據show.names
的名稱感到滿意,則不需要支持show.names
的名稱列表。 對於Boxplot
您必須為繪圖提供一個名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.