4

How would I do a bar plot of the frequency of non-numerical data using R?

e.g. if given v = c("B","A","B","A","B","D","C","D","D","D","C")

I want to get a bar plot in which each bar represents a unique value from the vector and the height of each bar to correspond with the frequency of that value:

enter image description here

4

1 に答える 1

11

Calculate the table of values for the barplot using the table() function, e.g.:

v <- c("B","A","B","A","B","D","C","D","D","D","C")
barplot(table(v))

This produces

barplot example figure

于 2012-09-18T22:18:00.897 に答える