[R] Legend Clipping

Beck, Kenneth (STP) Kenneth.Beck at bsci.com
Fri Apr 18 19:46:04 CEST 2008


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.



More information about the R-help mailing list