Re: [R] Bar Charts

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Sun, 11 May 2008 20:54:00 +1000

hoogeebear wrote:
> Hi,
>
> I created some bar charts. My first one is concerned with males, and my
> second concerned with females.
> Is there a way I can put the charts into one chart? There is 2 different
> columns in each file. Here is my new file containing males and females:
>
> gender,familar
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,No
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,No
> Female,Yes
> Female,No
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Female,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,No
> Male,No
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,Yes
> Male,No
> Male,Yes
> Male,Yes
>
> Here is the code I use for creating a female chart:
> library(plotrix)
> library(prettyR)
> female_familar <-read.table("C://females.csv", sep=",", header=TRUE)
> barp(rbind(rep(length(female_familar$gender),2),freq(female_familar$familar)[[1]]),
> ylab="20 Females participated in the survey",
> col=4:5,names.arg=c("Females No(3)","Females Yes(17)"))
> legend("topright",c("Females","Familarity"),fill=4:5)
>
> Does the above need to change much to include males and females in the one
> bar chart?
>
Hi Jack,
If your data frame is named "hg":

barp(table(hg),names.arg=levels(hg$familar),   col=c(2,4),legend.lab=levels(hg$gender))

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 11 May 2008 - 10:59:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 11 May 2008 - 11:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive