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 <abdoulayesar at gmail.com> 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<snip>
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 <marc_schwartz at me.com> 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 <abdoulayesar at gmail.com> 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 > > <snip>[[alternative HTML version deleted]]
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 <abdoulayesar at gmail.com> 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 <marc_schwartz at me.com> 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 <abdoulayesar at gmail.com> 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 >> >> <snip> >