1

I could not create barplot with following data frame

                    Age     Male.Average   Female.Average
   ---------------------------------------------------------    
1:       0-19 Childhood     20.29543       18.14773
2:    20-39 Young Adult     22.35352       22.41548
3: 40-64 Mid Aged Adult     23.75663       23.64908
4:     65-84 Senior Age     21.45002       21.71446
5:   85+ Old Senior Age     21.72200       21.31565

I want to create grouped barplot like x= age, y= male.average, female.average in beside. It gives error:

Error in barplot.default(d) : 'height' must be a vector or a matrix

1 Answer 1

2

Assuming that we have a data.frame

barplot(`colnames<-`(t(df1[-1]), df1[,1]), beside=TRUE, 
    legend.text = TRUE, col = c("red", "green"), 
    args.legend = list(x = "topleft", bty = "n", inset=c(-0.05, 0)))

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.