[R] Beside Barplot

David L Carlson dcarlson at tamu.edu
Mon Aug 20 21:14:47 CEST 2012


Sure but which way?

> dput(mydata)
structure(list(opinion = structure(c(4L, 5L, 1L, 2L, 3L), .Label = c("50-50
Chance", 
"A good chance", "Almost certain", "Almost no chance", "Probably Not"
), class = "factor"), female = c(96, 426, 696, 663, 486), male = c(98, 
286, 720, 758, 597)), .Names = c("opinion", "female", "male"), row.names =
c(NA, 
-5L), class = "data.frame")

> with(mydata, barplot(cbind(female, male), ylim=c(0, 900), beside=TRUE,
legend.text=opinion, args.legend=list(x="top", ncol=3)))
> with(mydata, barplot(t(cbind(female, male)), names.arg=opinion,
beside=TRUE, cex.names=.8, legend.text=TRUE))

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of darnold
> Sent: Monday, August 20, 2012 1:01 PM
> To: r-help at r-project.org
> Subject: [R] Beside Barplot
> 
> All,
> 
> Is there a way to get a barplot with beside for the following without
> reshaping mydata?
> 
> 
> opinion <- c("Almost no chance", "Probably Not","50-50 Chance","A good
> chance","Almost certain")
> female <- c(96,426,696,663,486)
> male <- c(98,286,720,758,597)
> mydata<-data.frame(opinion,female,male)
> 
> Thanks
> 
> David
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Beside-
> Barplot-tp4640807.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list