Re: [R] probelm with xlab ylab and xaxp barplot
Hi Marc, I have something very close now, and think to leave it like that. Thank you so much for your help to solve the problem. Cheers, asarr On Mon, Jul 25, 2016 at 6:03 PM, Marc Schwartz wrote: > Hi, > > First, I noted again that you still have: > >xaxp=c(181,2005,1) > > in the first barplot() call. Get rid of that, as barplot() does not use > normal axis ranges for the bar midpoints. > > Second, I do not see an indication that you are using the 'names.arg' > argument in barplot(), which supplies the vector of text to place below > each bar. If this is correct, then you want the basic barplot() call to > look something like: > > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", > names.arg = 1981:2005, > col=ifelse(z1>0,"green","brown")) > > where names.arg on the second line is the vector of years from 1981 to > 2005. If the data passed to barplot() have name attributes (for example, > they are the result of using table() on a vector), those would be used, but > I am guessing that your z* vectors are just numeric vectors without labels. > > If you then need to further adjust the axes to make more room below the > plots, adjust the first element of par(mar) until the default axes show. > > For example: > > par(mar = c(6, 4, 4, 2)) > > where 6 replaces the default 5 for the first element. You may need to go > higher if the text is still not showing. If need be, increase it further > slowly to view the impact. You can also change by less than a full integer > (e.g. 5.5, 6.25, etc.) as you may need. At some point, you will overshoot > with too much room and you can then back down slowly. > > Using this approach, each plot will have a similar size as you adjust the > margins and then look similar visually, presuming that the axis ranges are > the same for each. > > Regards, > > Marc > > > > On Jul 25, 2016, at 11:56 AM, Abdoulaye SARR > wrote: > > > > Hi Marc, > > > > According to your guidance the labels are almost at the right place when > adjusting mar values. > > > > A remaining need is to have the x axis at least for the two bottom > figures as date from 1981 to 2005. Do you think this is doable. Ylim is > fine but how tots in this case xlim. > > > > Best regards, > > > > asarr > > Le 25 juil. 2016 à 14:28, Marc Schwartz a écrit : > > > >> Hi, > >> > >> If your code below is a verbatim copy and paste, you still have the > following two lines active: > >> > >> par(mar=rep(2,4)) > >> > >> and > >> > >> op <- par(oma=c(1,2,3,5)) > >> > >> Comment out both of those lines and then see what the result looks like. > >> > >> As I noted before, try the plot **without any modifications** to the > default margin values. Then adjust from there, which may require you to > increase, not decrease, the values from their defaults in order to have > room for your text. > >> > >> The values you have for par(mar) above, for example, reduce the values > to 2 for each side from the default, which is: > >> > >> c(5, 4, 4, 2) + 0.1. > >> > >> So that alone will likely result in there not being enough room for > your axis labels. > >> > >> You may also have to create the barplot without any default annotation > created by the function itself and then add it with ?axis, ?text and > ?mtext. You may also have to reduce the size of the font itself, which is > done via the cex* arguments to barplot() and the additional annotation > functions mentioned in the prior sentence. > >> > >> Regards, > >> > >> Marc > >> > >> > >>> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR > wrote: > >>> > >>> > > Hi Marc and Others, > >>> > >>> > >>> I am still struggling to have my slab and ylab displayed on a bar > plot. Marc did useful advise on playing with mar settings. I tried may > combinations and can�t have it work. > >>> > >>> I paste the code I am suing hoping guidance on solving this issue. > >>> > >>> > >>> > >>> > >>> ## extract works for all time steps > >>> d1<-read.nc(gp) > >>> > >>> d2<-read.nc(er) > >>> > >>> d3<-read.nc(me) > >>> > >>> d4<-read.nc(ne) > >>> > >>> d5<-read.nc(ar) > >>> > >>> d6<-read.nc(cc) > >>> > >>> d7<-read.nc(mr) > >>> > >>> d8<-read.nc(ic) > >>> > >>> z1<-d1$spei > >>> z2<-d2$spei > >>> z3<-d3$spei > >>> z4<-d4$spei > >>> z5<-d5$spei > >>> z6<-d6$spei > >>> z7<-d7$spei > >>> z8<-d8$spei > >>> #par(oma=c(2,2,2,2)) # all sides have 3 lines of space > >>> > >>> par(mar=rep(2,4)) > >>> #par(mar=c(5.1, 4.1, 2.1, 2.1)) > >>> #par(mai=c(1.02,0.82,0.82,0.42)) > >>> op <- par(oma=c(1,2,3,5)) > >>> #op <- par(oma=c(6,5,0,0)) > >>> par(mfrow=c(4,2)) > >>> > >>> line = 3 > >>> > >>> barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", > xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown")) > >>> > >>> mtext("a") > >>> barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z2>0,"green","brown")) > >>> mtext("b") > >>> barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", > col=ifelse(z3>0,"green","brown")) > >>> mtext("c") > >>> barplot(z4, xlab="Years", ylab="spei",
Re: [R] probelm with xlab ylab and xaxp barplot
Hi Marc, According to your guidance the labels are almost at the right place when adjusting mar values. A remaining need is to have the x axis at least for the two bottom figures as date from 1981 to 2005. Do you think this is doable. Ylim is fine but how tots in this case xlim. Best regards, asarr Le 25 juil. 2016 à 14:28, Marc Schwartz a écrit : > Hi, > > If your code below is a verbatim copy and paste, you still have the following > two lines active: > > par(mar=rep(2,4)) > > and > > op <- par(oma=c(1,2,3,5)) > > Comment out both of those lines and then see what the result looks like. > > As I noted before, try the plot **without any modifications** to the default > margin values. Then adjust from there, which may require you to increase, not > decrease, the values from their defaults in order to have room for your text. > > The values you have for par(mar) above, for example, reduce the values to 2 > for each side from the default, which is: > > c(5, 4, 4, 2) + 0.1. > > So that alone will likely result in there not being enough room for your axis > labels. > > You may also have to create the barplot without any default annotation > created by the function itself and then add it with ?axis, ?text and ?mtext. > You may also have to reduce the size of the font itself, which is done via > the cex* arguments to barplot() and the additional annotation functions > mentioned in the prior sentence. > > Regards, > > Marc > > >> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR wrote: >> >> Hi Marc and Others, >> >> >> I am still struggling to have my slab and ylab displayed on a bar plot. Marc >> did useful advise on playing with mar settings. I tried may combinations and >> can�t have it work. >> >> I paste the code I am suing hoping guidance on solving this issue. >> >> >> >> >> ## extract works for all time steps >> d1<-read.nc(gp) >> >> d2<-read.nc(er) >> >> d3<-read.nc(me) >> >> d4<-read.nc(ne) >> >> d5<-read.nc(ar) >> >> d6<-read.nc(cc) >> >> d7<-read.nc(mr) >> >> d8<-read.nc(ic) >> >> z1<-d1$spei >> z2<-d2$spei >> z3<-d3$spei >> z4<-d4$spei >> z5<-d5$spei >> z6<-d6$spei >> z7<-d7$spei >> z8<-d8$spei >> #par(oma=c(2,2,2,2)) # all sides have 3 lines of space >> >> par(mar=rep(2,4)) >> #par(mar=c(5.1, 4.1, 2.1, 2.1)) >> #par(mai=c(1.02,0.82,0.82,0.42)) >> op <- par(oma=c(1,2,3,5)) >> #op <- par(oma=c(6,5,0,0)) >> par(mfrow=c(4,2)) >> >> line = 3 >> >> barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), >> col=ifelse(z1>0,"green","brown")) >> >> mtext("a") >> barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z2>0,"green","brown")) >> mtext("b") >> barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", >> col=ifelse(z3>0,"green","brown")) >> mtext("c") >> barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z4>0,"green","brown")) >> mtext("d") >> barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z5>0,"green","brown")) >> mtext("e") >> barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z6>0,"green","brown")) >> mtext("f") >> barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z7>0,"green","brown")) >> mtext("g") >> barplot(z8, ylim=c(-2,2), xlab="Years", ylab="spei", >> col=ifelse(z8>0,"green","brown")) >> mtext("h") >> par(op) >> >> Another solution with ggplot2 or lattice also welcome. >> >> >> Best regards, >> >> asarr > > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] probelm with xlab ylab and xaxp barplot
Hi, First, I noted again that you still have: xaxp=c(181,2005,1) in the first barplot() call. Get rid of that, as barplot() does not use normal axis ranges for the bar midpoints. Second, I do not see an indication that you are using the 'names.arg' argument in barplot(), which supplies the vector of text to place below each bar. If this is correct, then you want the basic barplot() call to look something like: barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", names.arg = 1981:2005, col=ifelse(z1>0,"green","brown")) where names.arg on the second line is the vector of years from 1981 to 2005. If the data passed to barplot() have name attributes (for example, they are the result of using table() on a vector), those would be used, but I am guessing that your z* vectors are just numeric vectors without labels. If you then need to further adjust the axes to make more room below the plots, adjust the first element of par(mar) until the default axes show. For example: par(mar = c(6, 4, 4, 2)) where 6 replaces the default 5 for the first element. You may need to go higher if the text is still not showing. If need be, increase it further slowly to view the impact. You can also change by less than a full integer (e.g. 5.5, 6.25, etc.) as you may need. At some point, you will overshoot with too much room and you can then back down slowly. Using this approach, each plot will have a similar size as you adjust the margins and then look similar visually, presuming that the axis ranges are the same for each. Regards, Marc > On Jul 25, 2016, at 11:56 AM, Abdoulaye SARR wrote: > > Hi Marc, > > According to your guidance the labels are almost at the right place when > adjusting mar values. > > A remaining need is to have the x axis at least for the two bottom figures as > date from 1981 to 2005. Do you think this is doable. Ylim is fine but how > tots in this case xlim. > > Best regards, > > asarr > Le 25 juil. 2016 à 14:28, Marc Schwartz a écrit : > >> Hi, >> >> If your code below is a verbatim copy and paste, you still have the >> following two lines active: >> >> par(mar=rep(2,4)) >> >> and >> >> op <- par(oma=c(1,2,3,5)) >> >> Comment out both of those lines and then see what the result looks like. >> >> As I noted before, try the plot **without any modifications** to the default >> margin values. Then adjust from there, which may require you to increase, >> not decrease, the values from their defaults in order to have room for your >> text. >> >> The values you have for par(mar) above, for example, reduce the values to 2 >> for each side from the default, which is: >> >> c(5, 4, 4, 2) + 0.1. >> >> So that alone will likely result in there not being enough room for your >> axis labels. >> >> You may also have to create the barplot without any default annotation >> created by the function itself and then add it with ?axis, ?text and ?mtext. >> You may also have to reduce the size of the font itself, which is done via >> the cex* arguments to barplot() and the additional annotation functions >> mentioned in the prior sentence. >> >> Regards, >> >> Marc >> >> >>> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR wrote: >>> >>> > Hi Marc and Others, >>> >>> >>> I am still struggling to have my slab and ylab displayed on a bar plot. >>> Marc did useful advise on playing with mar settings. I tried may >>> combinations and can�t have it work. >>> >>> I paste the code I am suing hoping guidance on solving this issue. >>> >>> >>> >>> >>> ## extract works for all time steps >>> d1<-read.nc(gp) >>> >>> d2<-read.nc(er) >>> >>> d3<-read.nc(me) >>> >>> d4<-read.nc(ne) >>> >>> d5<-read.nc(ar) >>> >>> d6<-read.nc(cc) >>> >>> d7<-read.nc(mr) >>> >>> d8<-read.nc(ic) >>> >>> z1<-d1$spei >>> z2<-d2$spei >>> z3<-d3$spei >>> z4<-d4$spei >>> z5<-d5$spei >>> z6<-d6$spei >>> z7<-d7$spei >>> z8<-d8$spei >>> #par(oma=c(2,2,2,2)) # all sides have 3 lines of space >>> >>> par(mar=rep(2,4)) >>> #par(mar=c(5.1, 4.1, 2.1, 2.1)) >>> #par(mai=c(1.02,0.82,0.82,0.42)) >>> op <- par(oma=c(1,2,3,5)) >>> #op <- par(oma=c(6,5,0,0)) >>> par(mfrow=c(4,2)) >>> >>> line = 3 >>> >>> barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), >>> col=ifelse(z1>0,"green","brown")) >>> >>> mtext("a") >>> barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), >>> col=ifelse(z2>0,"green","brown")) >>> mtext("b") >>> barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", >>> col=ifelse(z3>0,"green","brown")) >>> mtext("c") >>> barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), >>> col=ifelse(z4>0,"green","brown")) >>> mtext("d") >>> barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), >>> col=ifelse(z5>0,"green","brown")) >>> mtext("e") >>> barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), >>> col=ifelse(z6>0,"green","brown")) >>> mtext("f") >>> barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), >>> col=ifelse(z7>0,"green","brow
Re: [R] probelm with xlab ylab and xaxp barplot
Hi, If your code below is a verbatim copy and paste, you still have the following two lines active: par(mar=rep(2,4)) and op <- par(oma=c(1,2,3,5)) Comment out both of those lines and then see what the result looks like. As I noted before, try the plot **without any modifications** to the default margin values. Then adjust from there, which may require you to increase, not decrease, the values from their defaults in order to have room for your text. The values you have for par(mar) above, for example, reduce the values to 2 for each side from the default, which is: c(5, 4, 4, 2) + 0.1. So that alone will likely result in there not being enough room for your axis labels. You may also have to create the barplot without any default annotation created by the function itself and then add it with ?axis, ?text and ?mtext. You may also have to reduce the size of the font itself, which is done via the cex* arguments to barplot() and the additional annotation functions mentioned in the prior sentence. Regards, Marc > On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR wrote: > > >>> Hi Marc and Others, > > > I am still struggling to have my slab and ylab displayed on a bar plot. Marc > did useful advise on playing with mar settings. I tried may combinations and > can�t have it work. > > I paste the code I am suing hoping guidance on solving this issue. > > > > > ## extract works for all time steps > d1<-read.nc(gp) > > d2<-read.nc(er) > > d3<-read.nc(me) > > d4<-read.nc(ne) > > d5<-read.nc(ar) > > d6<-read.nc(cc) > > d7<-read.nc(mr) > > d8<-read.nc(ic) > > z1<-d1$spei > z2<-d2$spei > z3<-d3$spei > z4<-d4$spei > z5<-d5$spei > z6<-d6$spei > z7<-d7$spei > z8<-d8$spei > #par(oma=c(2,2,2,2)) # all sides have 3 lines of space > > par(mar=rep(2,4)) > #par(mar=c(5.1, 4.1, 2.1, 2.1)) > #par(mai=c(1.02,0.82,0.82,0.42)) > op <- par(oma=c(1,2,3,5)) > #op <- par(oma=c(6,5,0,0)) > par(mfrow=c(4,2)) > > line = 3 > > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), > col=ifelse(z1>0,"green","brown")) > > mtext("a") > barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z2>0,"green","brown")) > mtext("b") > barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", > col=ifelse(z3>0,"green","brown")) > mtext("c") > barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z4>0,"green","brown")) > mtext("d") > barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z5>0,"green","brown")) > mtext("e") > barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z6>0,"green","brown")) > mtext("f") > barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), > col=ifelse(z7>0,"green","brown")) > mtext("g") > barplot(z8, ylim=c(-2,2), xlab="Years", ylab="spei", > col=ifelse(z8>0,"green","brown")) > mtext("h") > par(op) > > Another solution with ggplot2 or lattice also welcome. > > > Best regards, > > asarr __ R-help@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.
Re: [R] probelm with xlab ylab and xaxp barplot
>> Hi Marc and Others, I am still struggling to have my slab and ylab displayed on a bar plot. Marc did useful advise on playing with mar settings. I tried may combinations and can�t have it work. I paste the code I am suing hoping guidance on solving this issue. ## extract works for all time steps d1<-read.nc(gp) d2<-read.nc(er) d3<-read.nc(me) d4<-read.nc(ne) d5<-read.nc(ar) d6<-read.nc(cc) d7<-read.nc(mr) d8<-read.nc(ic) z1<-d1$spei z2<-d2$spei z3<-d3$spei z4<-d4$spei z5<-d5$spei z6<-d6$spei z7<-d7$spei z8<-d8$spei #par(oma=c(2,2,2,2)) # all sides have 3 lines of space par(mar=rep(2,4)) #par(mar=c(5.1, 4.1, 2.1, 2.1)) #par(mai=c(1.02,0.82,0.82,0.42)) op <- par(oma=c(1,2,3,5)) #op <- par(oma=c(6,5,0,0)) par(mfrow=c(4,2)) line = 3 barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown")) mtext("a") barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z2>0,"green","brown")) mtext("b") barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", col=ifelse(z3>0,"green","brown")) mtext("c") barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z4>0,"green","brown")) mtext("d") barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z5>0,"green","brown")) mtext("e") barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z6>0,"green","brown")) mtext("f") barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z7>0,"green","brown")) mtext("g") barplot(z8, ylim=c(-2,2), xlab="Years", ylab="spei", col=ifelse(z8>0,"green","brown")) mtext("h") par(op) Another solution with ggplot2 or lattice also welcome. Best regards, asarr >> >> >> On Wed, Jul 20, 2016 at 6:03 PM, Marc Schwartz wrote: >> >> > On Jul 20, 2016, at 4:00 AM, Abdoulaye SARR wrote: >> > >> > I have the color of my bar plot displayed correctly but don�t have xlab, >> > ylab and xaxp don�t show up. >> > >> > here is example of yearly data (25 years 1981-2005) >> >> head(z1) >> > [1] -0.1001726 0.2014272 -0.8556950 0.1920669 -0.8013520 1.3324949 >> > >> > code to display values >> > >> > par(mar=rep(2,4)) >> > op <- par(oma=c(5,7,1,1)) >> > par(mfrow=c(4,2)) >> > >> > line = 3 >> > >> > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), >> > col=ifelse(z1>0,"green","brown �)) >> > >> > hoe help on this issue >> > >> > Fipou >> >> >> Hi, >> >> First, a general comment, which is that barplots are typically good for >> displaying counts and percentages, not continuous data points or perhaps >> estimates of means, etc. Your values for z1 above, suggest that you might be >> better off just plotting the points on the y axis against the years on the x >> axis. That is, for example: >> >> plot(1981:2005, z1, col = ifelse(z1 > 0, "green", "brown"), >>ylab = "spei", xlab = "Years", pch = 19) >> >> presuming that z1 has 25 values. >> >> That being said, some additional notes to hopefully guide you here with >> barplot(): >> >> 1. You appear to be wanting to plot a matrix of 8 plots in a 4 row by 2 >> column matrix. That is fine, but note that changing the graphic parameters >> associated with the spacing of margins, etc. in a matrix don't always >> provide a result similar to what you might find in a single plot. I would >> start by not adjusting par(mar) and par(oma) from their default values to >> get an idea of what the plot looks like with default settings and then >> modify from there so that you can see how any adjustments affect the result. >> You may be adjusting the margins for each plot and the outer margins of the >> overall matrix in a manner that conflicts. >> >> >> 2. In the case of a vertical barplot, the bars are not centered around >> integer values on the x axis, as they would be in say a boxplot. In the help >> for barplot() you will note that the Value section indicates that barplot >> returns a vector (by default) of the bar midpoints, which can then be used >> for annotation on the relevant axis. There are examples of the use of this >> on the barplot help page. Your values for 'xaxp' (which presumably has a >> typo for 1981, as 181) will not be correct here. Thus: >> >> MP <- barplot(z1, ...) >> >> where 'MP' will contain the individual bar midpoints and then you can use >> code like: >> >> axis(1, at = MP, labels = 1981:2005, ...) >> >> to place annotations below each bar. See ?axis as well as ?mtext for >> additional information on plot annotations. >> >> Another option is to use the names.arg argument in barplot, to provide the >> names for each bar: >> >> barplot(z1, names.arg = 1981:2005, ...) >> >> You will also likely have to adjust the font sizes for text spacing, as the >> defaults may be too large for all labels to display given the large number >> of bars. The cex* family of graphic parameters can be helpful. See the >> arguments in ?barplot and in ?par for more information. >> >> Regards, >> >> Marc Schwartz >> >> >
Re: [R] probelm with xlab ylab and xaxp barplot
> On Jul 20, 2016, at 4:00 AM, Abdoulaye SARR wrote: > > I have the color of my bar plot displayed correctly but don’t have xlab, > ylab and xaxp don’t show up. > > here is example of yearly data (25 years 1981-2005) >> head(z1) > [1] -0.1001726 0.2014272 -0.8556950 0.1920669 -0.8013520 1.3324949 > > code to display values > > par(mar=rep(2,4)) > op <- par(oma=c(5,7,1,1)) > par(mfrow=c(4,2)) > > line = 3 > > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), > col=ifelse(z1>0,"green","brown »)) > > hoe help on this issue > > Fipou Hi, First, a general comment, which is that barplots are typically good for displaying counts and percentages, not continuous data points or perhaps estimates of means, etc. Your values for z1 above, suggest that you might be better off just plotting the points on the y axis against the years on the x axis. That is, for example: plot(1981:2005, z1, col = ifelse(z1 > 0, "green", "brown"), ylab = "spei", xlab = "Years", pch = 19) presuming that z1 has 25 values. That being said, some additional notes to hopefully guide you here with barplot(): 1. You appear to be wanting to plot a matrix of 8 plots in a 4 row by 2 column matrix. That is fine, but note that changing the graphic parameters associated with the spacing of margins, etc. in a matrix don't always provide a result similar to what you might find in a single plot. I would start by not adjusting par(mar) and par(oma) from their default values to get an idea of what the plot looks like with default settings and then modify from there so that you can see how any adjustments affect the result. You may be adjusting the margins for each plot and the outer margins of the overall matrix in a manner that conflicts. 2. In the case of a vertical barplot, the bars are not centered around integer values on the x axis, as they would be in say a boxplot. In the help for barplot() you will note that the Value section indicates that barplot returns a vector (by default) of the bar midpoints, which can then be used for annotation on the relevant axis. There are examples of the use of this on the barplot help page. Your values for 'xaxp' (which presumably has a typo for 1981, as 181) will not be correct here. Thus: MP <- barplot(z1, ...) where 'MP' will contain the individual bar midpoints and then you can use code like: axis(1, at = MP, labels = 1981:2005, ...) to place annotations below each bar. See ?axis as well as ?mtext for additional information on plot annotations. Another option is to use the names.arg argument in barplot, to provide the names for each bar: barplot(z1, names.arg = 1981:2005, ...) You will also likely have to adjust the font sizes for text spacing, as the defaults may be too large for all labels to display given the large number of bars. The cex* family of graphic parameters can be helpful. See the arguments in ?barplot and in ?par for more information. Regards, Marc Schwartz __ R-help@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.
[R] probelm with xlab ylab and xaxp barplot
I have the color of my bar plot displayed correctly but don’t have xlab, ylab and xaxp don’t show up. here is example of yearly data (25 years 1981-2005) > head(z1) [1] -0.1001726 0.2014272 -0.8556950 0.1920669 -0.8013520 1.3324949 code to display values par(mar=rep(2,4)) op <- par(oma=c(5,7,1,1)) par(mfrow=c(4,2)) line = 3 barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown »)) hoe help on this issue Fipou __ R-help@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.