[R] Beside Barplot

David L Carlson dcarlson at tamu.edu
Mon Aug 20 21:36:46 CEST 2012


Actually the second example should just be

> with(mydata, barplot(rbind(female, male), names.arg=opinion,
  beside=TRUE, cex.names=.8, legend.text=TRUE))

rbind() instead of t(cbind())
-------
David


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of David L Carlson
> Sent: Monday, August 20, 2012 2:15 PM
> To: 'darnold'; r-help at r-project.org
> Subject: Re: [R] Beside Barplot
> 
> 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.
> 
> ______________________________________________
> 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