Reputation: 155
I have a txt filde in which is storedthe information related tu clusters:
PID Cluster
123 1
234 1
2345 2
......
I can read the field and then, I've generated a data frame. I want to plot the data in bars, that indicates for example the number of patients in y axe and the cluster in x axe. In this case I want two bars with values 2 and 1 respectively. Thank you
Upvotes: 0
Views: 62
Reputation: 116
In base R:
patients = data.frame(PID = c(123, 234, 2345), Cluster = c(1,1,2))
pat.table = with(patients, table(Cluster))
barplot(pat.table)
Using ggplot2
require(ggplot2)
ggplot(patients, aes(x = factor(Cluster))) + geom_bar() + scale_x_discrete("Cluster")
Upvotes: 1