This question is related to: R: how to label the x-axis of a boxplot
When more than one column is plotted, names appear. But when only one column is plotted, name does not appear, even when names=.. argument is used:
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])
Following also do not work:
boxplot(ddf[,1], names='apple')
boxplot(ddf[,1], names=c('apple'))
How can I add name to the boxplot when only one column is used? Thanks for your help.
There is a show.names=
argument to bxp
, which boxplot
calls. You can thus do:
boxplot(ddf[1], show.names=TRUE)
Make sure this is ddf[1]
not ddf[,1]
though, so that the name is retained.
Maybe you can use 'xlab':
boxplot(ddf[,1], xlab="apple")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With