Jim: (a) There's no legend. (b) I am still curious as to why the OP's code didn't work, in that the "space=c(0,2)" argument seemed to have no effect. cheers, Rolf On 18/08/18 20:45, Jim Lemon wrote:> Hi citc, > Try this: > > geac<-matrix(c(9,9,8,8,8,23,23,23,23,22,27,27,27,25,24, > 19,19,19,20,20,17,17,17,18,19,8,8,8,9,9,2,2,3,3,3),ncol=5,byrow=TRUE) > library(plotrix) > barp(geac,names.arg=2014:2018,main="A level grades chemistry", > xlab="Year",ylab="Percentage of each grade",ylim=c(0,30), > col=c("white","lightblue","blue","orange","green","red","pink")) > > Jim > > On Fri, Aug 17, 2018 at 9:55 PM, <citc at disroot.org> wrote: >> R-users, >> >> Can someone please advise how to improve the code below that was used to produce the graph shown at the following hyperlink (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The request is to add space between the annual data groups. >> >> barplot(gceac[,3], xlab='year', ylab='percentage of each grade', col=c('aliceblue', 'aquamarine', 'blue', 'chocolate', 'darkgreen', 'firebrick', 'violet'), legend=gceac[1:7,2], args.legend = list(x = 40, y = 30, title='grades'), main='A-level grades, chemistry', beside=T, space=c(0,2), ylim=c(0,30)) >> years<-c(2014,2015,2016,2017,2018) >> mtext(years, side=1, at=c(5, 12, 19, 26, 33)) >> R-users, Can someone please advise how to improve the code below that was used to produce the graph shown at the following hyperlink (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The request is to add space between the annual data groups. barplot(gceac[,3], xlab='year', ylab='percentage of each grade', col=c('aliceblue', 'aquamarine', 'blue', 'chocolate', 'darkgreen', 'firebrick', 'violet'), legend=gceac[1:7,2], args.legend = list(x = 40, y = 30, title='grades'), main='A-level grades, chemistry', beside=T, space=c(0,2), ylim=c(0,30)) years<-c(2014,2015,2016,2017,2018) mtext(years, side=1, at=c(5, 12, 19, 26, 33))
Hi Rolf, That's what comes of being in a hurry. legend(4.1,30,c("A+","A","B","C","D","E","U"), fill=c("white","lightblue","blue","orange","green","red","pink")) and I thank you for alerting me to the fact that the legend arguments in barp don't position the legend properly. I'll fix it. Jim On Sun, Aug 19, 2018 at 9:52 AM, Rolf Turner <r.turner at auckland.ac.nz> wrote:> > Jim: > > (a) There's no legend. > > (b) I am still curious as to why the OP's code didn't work, in that > the "space=c(0,2)" argument seemed to have no effect. > > cheers, > > Rolf > > On 18/08/18 20:45, Jim Lemon wrote: >> >> Hi citc, >> Try this: >> >> geac<-matrix(c(9,9,8,8,8,23,23,23,23,22,27,27,27,25,24, >> 19,19,19,20,20,17,17,17,18,19,8,8,8,9,9,2,2,3,3,3),ncol=5,byrow=TRUE) >> library(plotrix) >> barp(geac,names.arg=2014:2018,main="A level grades chemistry", >> xlab="Year",ylab="Percentage of each grade",ylim=c(0,30), >> col=c("white","lightblue","blue","orange","green","red","pink")) >> >> Jim >> >> On Fri, Aug 17, 2018 at 9:55 PM, <citc at disroot.org> wrote: >>> >>> R-users, >>> >>> Can someone please advise how to improve the code below that was used to >>> produce the graph shown at the following hyperlink >>> (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The >>> request is to add space between the annual data groups. >>> >>> barplot(gceac[,3], xlab='year', ylab='percentage of each grade', >>> col=c('aliceblue', 'aquamarine', 'blue', 'chocolate', 'darkgreen', >>> 'firebrick', 'violet'), legend=gceac[1:7,2], args.legend = list(x = 40, y >>> 30, title='grades'), main='A-level grades, chemistry', beside=T, >>> space=c(0,2), ylim=c(0,30)) >>> years<-c(2014,2015,2016,2017,2018) >>> mtext(years, side=1, at=c(5, 12, 19, 26, 33)) >>> R-users, Can someone please advise how to improve the code below that was >>> used to produce the graph shown at the following hyperlink >>> (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The >>> request is to add space between the annual data groups. barplot(gceac[,3], >>> xlab='year', ylab='percentage of each grade', col=c('aliceblue', >>> 'aquamarine', 'blue', 'chocolate', 'darkgreen', 'firebrick', 'violet'), >>> legend=gceac[1:7,2], args.legend = list(x = 40, y = 30, title='grades'), >>> main='A-level grades, chemistry', beside=T, space=c(0,2), ylim=c(0,30)) >>> years<-c(2014,2015,2016,2017,2018) mtext(years, side=1, at=c(5, 12, 19, 26, >>> 33))
My guess is that space has no effect because (1) the first element is zero and (2) the code in OP's message has barplot(gceac[,3], ... i.e. barplot does not see a matrix, only a vector. To the OP, try formatting the data to be plotted as a matrix, not as a vector, then the space argument should be useful to add space between groups. Peter On Sat, Aug 18, 2018 at 4:53 PM Rolf Turner <r.turner at auckland.ac.nz> wrote:> > > Jim: > > (a) There's no legend. > > (b) I am still curious as to why the OP's code didn't work, in that > the "space=c(0,2)" argument seemed to have no effect. > > cheers, > > Rolf > > On 18/08/18 20:45, Jim Lemon wrote: > > Hi citc, > > Try this: > > > > geac<-matrix(c(9,9,8,8,8,23,23,23,23,22,27,27,27,25,24, > > 19,19,19,20,20,17,17,17,18,19,8,8,8,9,9,2,2,3,3,3),ncol=5,byrow=TRUE) > > library(plotrix) > > barp(geac,names.arg=2014:2018,main="A level grades chemistry", > > xlab="Year",ylab="Percentage of each grade",ylim=c(0,30), > > col=c("white","lightblue","blue","orange","green","red","pink")) > > > > Jim > > > > On Fri, Aug 17, 2018 at 9:55 PM, <citc at disroot.org> wrote: > >> R-users, > >> > >> Can someone please advise how to improve the code below that was used to produce the graph shown at the following hyperlink (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The request is to add space between the annual data groups. > >> > >> barplot(gceac[,3], xlab='year', ylab='percentage of each grade', col=c('aliceblue', 'aquamarine', 'blue', 'chocolate', 'darkgreen', 'firebrick', 'violet'), legend=gceac[1:7,2], args.legend = list(x = 40, y = 30, title='grades'), main='A-level grades, chemistry', beside=T, space=c(0,2), ylim=c(0,30)) > >> years<-c(2014,2015,2016,2017,2018) > >> mtext(years, side=1, at=c(5, 12, 19, 26, 33)) > >> R-users, Can someone please advise how to improve the code below that was used to produce the graph shown at the following hyperlink (https://chemistryinthecity.neocities.org/content/entry1808.html#17)? The request is to add space between the annual data groups. barplot(gceac[,3], xlab='year', ylab='percentage of each grade', col=c('aliceblue', 'aquamarine', 'blue', 'chocolate', 'darkgreen', 'firebrick', 'violet'), legend=gceac[1:7,2], args.legend = list(x = 40, y = 30, title='grades'), main='A-level grades, chemistry', beside=T, space=c(0,2), ylim=c(0,30)) years<-c(2014,2015,2016,2017,2018) mtext(years, side=1, at=c(5, 12, 19, 26, 33)) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
On 19/08/18 16:58, Peter Langfelder wrote:> My guess is that space has no effect because (1) the first element is > zero and (2) the code in OP's message has > barplot(gceac[,3], ... > > i.e. barplot does not see a matrix, only a vector. > > To the OP, try formatting the data to be plotted as a matrix, not as a > vector, then the space argument should be useful to add space between > groups.Thanks Peter. That would appear to be a sound analysis. Thanks for the insight. cheers, Rolf -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
On 19/08/18 16:12, Jim Lemon wrote:> Hi Rolf, > That's what comes of being in a hurry. > > legend(4.1,30,c("A+","A","B","C","D","E","U"), > fill=c("white","lightblue","blue","orange","green","red","pink")) > > and I thank you for alerting me to the fact that the legend arguments > in barp don't position the legend properly. I'll fix it.And I wasn't even aware that I was doing any alerting! :-) cheers, Rolf -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
citc m@iii@g oii disroot@org
2018-Aug-19 14:15 UTC
[R] [FORGED] Re: bar plot add space to group data
August 19, 2018 4:58 AM, "Peter Langfelder" <peter.langfelder at gmail.com> wrote:> To the OP, try formatting the data to be plotted as a matrix, not as a > vectorCSV data provided in a previous message; is not the data formatted as a matrix?
On Sun, Aug 19, 2018 at 7:15 AM <citc at disroot.org> wrote:> > August 19, 2018 4:58 AM, "Peter Langfelder" <peter.langfelder at gmail.com> wrote: > > > To the OP, try formatting the data to be plotted as a matrix, not as a > > vector > > CSV data provided in a previous message; is not the data formatted as a matrix?I meant the data you give to barplot - your code supplies only the third column of the data frame, so barplot only sees a vector. I would try something like plotData = do.call(cbind, tapply(csv.data$percentage, csv.data$year, identity)) barplot(plotData, <rest of your argument>) Peter