I have a dataset that includes a "Gender" element. That is coded 1 for male and 2 for female. I'm trying to create a simple bar chart using lattice in R to compare the number of males and females. This is the code I am trying:
> barchart(equal.count(Gender),
+ horizontal=FALSE,
+ names.arg = c("Male","Female"))
This code does, in fact, create a bar chart with the correct heights for each bar. However, the labels for the bars are "1" and "2"; and I would like to use something more meaningful, like "Male" and "Female".
I've tried several variations on line #3 above, including; key.legend=c("Male","Female") -- key.title=c("Male","Female") -- key.title=list("Male","Female") -- labels=list("Male","Female"). It seems that no matter what I do the chart still shows "1" and "2" as labels for the two bars. How can I create a bar chart where the labels are more meaningful than "1" and "2"? Thanks for any help you can offer.
You need the xlab argument: