Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bar plot of non-numerical data in R

Tags:

plot

r

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

like image 443
Pi_ Avatar asked Dec 20 '22 16:12

Pi_


1 Answers

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

like image 77
Gavin Simpson Avatar answered Jan 25 '23 23:01

Gavin Simpson