[R] probelm with xlab ylab and xaxp barplot

Marc Schwartz marc_schwartz at me.com
Mon Jul 25 16:28:12 CEST 2016


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>



More information about the R-help mailing list