Re: [R] Legend Clipping

From: Beck, Kenneth (STP) <Kenneth.Beck_at_bsci.com>
Date: Fri, 18 Apr 2008 12:46:04 -0500

Here is a better example. I am also trying to put gaps between the bars on the graphs, and this work-around is the only way I can make it work satisfactorily. Any suggestions about that?

windows();
nf <- layout(matrix(c(1,2,5,0,3,4),3,2,byrow=TRUE), c(2.2,2.2), c(2.2,1,2.2), TRUE)
layout.show(nf);

par(font.axis=2);
par(font.lab=2);
ylimit=c(0,1.2);
pmn <- matrix(c(1:5), nrow=5, ncol=1)
pmn[,1]=c(0,0.8,0,0.75,0);
barplot(pmn,ylab="Slopes",beside=TRUE,ylim=ylimit,xlim=c(1,6.0), col = c(NA,"blue", NA, "red",NA));

par(font.axis=2);
par(font.lab=2);
ylimit=c(0,1.2);
pmn <- matrix(c(1:5), nrow=5, ncol=1)
pstd=pmn;
pmn[,1]=c(0,0.8,0,0.75,0);
barplot(pmn,ylab="Slopes",beside=TRUE,ylim=ylimit,xlim=c(1,6.0), col = c(NA,"blue", NA, "red",NA));

par(font.axis=2);
par(font.lab=2);
ylimit=c(0,1.2);
pmn <- matrix(c(1:5), nrow=5, ncol=1)
pstd=pmn;
pmn[,1]=c(0,0.8,0,0.75,0);
barplot(pmn,ylab="Slopes",beside=TRUE,ylim=ylimit,xlim=c(1,6.0), col = c(NA,"blue", NA, "red",NA));

par(font.axis=2);
par(font.lab=2);
ylimit=c(0,1.2);
pmn <- matrix(c(1:5), nrow=5, ncol=1)
pstd=pmn;
pmn[,1]=c(0,0.8,0,0.75,0);
barplot(pmn,ylab="Slopes",beside=TRUE,ylim=ylimit,xlim=c(1,6.0), col = c(NA,"blue", NA, "red",NA));

plot(1, type="n", axes=FALSE, xlab="", ylab="",ylim=c(0,2),xlim=c(0,2)); legend(0.5,0.5, legend = c("CPX","Home"), bty="n", fill=c("blue","red"),lwd=1, cex=1, xjust=0.5, yjust=0.4);

-----Original Message-----
To: r-help_at_r-project.org
Subject: [R] Legend Clipping

I am having trouble with legends clipping, not sure how to control that. Here is my latest code to demo. I want the legend to show up in the center of the window, in fairly large font. Right now, font is too small, but if I increase it, the legend clips even more. In this simplified example, the plots are dummy (I took them from an example), my actual plots only have two bars, corresponding to the legend.

windows();
nf1 <- layout(matrix(1), widths=lcm(6), heights=lcm(6)) nf <- layout(matrix(c(1,2,5,0,3,4),3,2,byrow=TRUE), c(2.2,2.2), c(2.2,1,2.2), TRUE) layout.show(nf); # par(mfrow=c(3,2));

par(font.axis=2);
par(font.lab=2);
# pmn=t(pmn);
tN <- table(Ni <- stats::rpois(100, lambda=5)) barplot(tN, col=rainbow(20))

# par (mfg=c(1,2));
par(font.axis=2);
par(font.lab=2);
tN <- table(Ni <- stats::rpois(100, lambda=5)) barplot(tN, col=rainbow(20))

# par (mfg=c(2,1));

par(font.axis=2);
par(font.lab=2);
tN <- table(Ni <- stats::rpois(100, lambda=5)) barplot(tN, col=rainbow(20))

# par (mfg=c(2,2));

par(font.axis=2);
par(font.lab=2);
tN <- table(Ni <- stats::rpois(100, lambda=5)) barplot(tN, col=rainbow(20))

# par (mfg=c(3,1));
plot(1, type="n", axes=FALSE, xlab="", ylab="",ylim=c(0,2),xlim=c(0,2));
# legend(1,0.8, legend = c("CPX","Home"), bty="n",
fill=c("blue","red"),lwd=1, cex=1, xjust=0.5, yjust=0.4); # ltest=legend("center", legend = c("CPX","Home"), bty="n", fill=c("blue","red"),lwd=1, cex=1, xjust=0.5, yjust=0.4,trace=TRUE,plot=FALSE); legend(0.5,0.5, legend = c("CPX","Home"), bty="n", fill=c("blue","red"),lwd=1, cex=1, xjust=0.5, yjust=0.4);



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. Received on Fri 18 Apr 2008 - 18:50:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Apr 2008 - 13:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive