[R] Legend Clipping

Beck, Kenneth (STP) Kenneth.Beck at bsci.com
Fri Apr 18 17:41:30 CEST 2008


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);




More information about the R-help mailing list