[R] Barplot - Beginners Question
Boris Steipe
boris.steipe at utoronto.ca
Mon Oct 5 03:59:36 CEST 2015
On Oct 4, 2015, at 7:39 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> You'll get what you want if you use as.matrix(datentabelle)[,1]
> instead of datentabelle[,1].
This happens to work in this particular case, but fails if the data frame contains text columns.
Example:
datentabelle <- cbind(datentabelle, text = sample(letters, nrow(datentabelle)))
barplot(as.matrix(datentabelle)[,1])
R> Error in -0.01 * height : non-numeric argument to binary operator
Therefore I would get the row names from your data frame with rownames(datentabelle), and use them as the names.arg argument of barplot():
barplot(datentabelle[,1], names.arg=rownames(datentabelle))
Cheers,
Boris
More information about the R-help
mailing list