0

I have a data.frame and I would like to draw a grouped barplot for two different columns.

Below are the two columns I care about.

str(credit_arff)

$ checking_status       : Factor w/ 4 levels "<0",">=200","0<=X<200",..:
$ class                 : Factor w/ 2 levels "bad","good":

I can draw the barplot for checking_status by barplot(mydata$checking_status) (shown below) but how can I draw a barplot so that it represents how many have corresponding value of good or bad.

Ideally I would like to have different colure in each bar with each representing good or bad

enter image description here

birdy
  • 9,286
  • 24
  • 107
  • 171

1 Answers1

1

There are quite a few ways to do this. See this post.

QuickR is also a good reference for this sort of thing.

For your particular case, you can do this using base graphics:

credit_arff <- data.frame(
  checking_status = c("<0", "<0", "<0", ">=200", ">=200", "0<=X<200", "0<=X<200", "0<=X<200", "0<=X<200", "no checking", "no checking", "no checking"),
  class = c("bad", "bad", "good", "bad", "good", "bad", "bad", "good", "bad", "good", "good", "bad")
)

df <- table(credit_arff$class, credit_arff$checking_status)
barplot(df, beside=T, col=c("red", "blue"), legend=rownames(df))

your grouped bar chart

Community
  • 1
  • 1
ajb
  • 692
  • 6
  • 16