Yufan Fei
Yufan Fei

Reputation: 69

How to change factors to be grouped in a barplot

I tried to do a barplot to a factorial anova dataset by using R. However, R automatically plots each bar corresponds to different columns of my dataset matrix. How can I do a barplot with each bar corresponds to different rows instead?

             High demand  Low demand  None
Difficult         934        739       465      
Easy              517        396       392

Upvotes: 0

Views: 98

Answers (1)

Robert
Robert

Reputation: 5152

Try one of this:

barplot(as.matrix(ab_group),legend.text = TRUE,col=1:nrow(ab_group))
barplot(as.matrix(ab_group),legend.text = TRUE,
        beside=T,col=1:nrow(ab_group))
barplot(as.matrix(t(ab_group)),legend.text = TRUE,col=1:ncol(ab_group))
barplot(as.matrix(t(ab_group)),legend.text = TRUE,
        beside=T,col=1:ncol(ab_group))

The last one is here:

Upvotes: 1

Related Questions