Plotting number of times a name occurs in a column (histogram)

99 views Asked by At

I have a list of names sorted, like below:

ACVR2B
ADAM19
ADAM29
ADAM29
ADAMTS1
ADAMTS1
ADAMTS1
ADAMTS12
ADAMTS16
ADAMTS16
ADAMTS16
ADAMTS17
ADAMTS17
ADAMTSL1
ADCY10

would like to plot them as a histogram. It is very easy when these are values but with characters how can I do it in R or in open office?

Thank you

2

There are 2 answers

4
Andrie On BEST ANSWER

Try plotting the result of table(). The function table() computes the cross-tabulation frequency, which is exactly what you want.

set.seed(42)
x <- sample(letters, 100, replace = TRUE)
plot(table(x))

enter image description here


To plot the sorted values, try this:

z <- sort(table(x))
plot(z, xaxt="n", type="h")
axis(1, at=seq_along(z), names(z))

enter image description here

0
Angelo On

Given to what Andrie suggested: I did this:

Letter<-read.table("letters", header=T)

x <- sample(Letters, replace = F)
plot(sort(table(x)))

but the things is when, I want to plot in a descending order with only top 10 I miss out on the labels.

Can anyone suggest how to fix it and get only top 10.