[R] multiple plots problem

Kay Cichini Kay.Cichini at uibk.ac.at
Tue Apr 20 14:58:39 CEST 2010


hello,

i try to plot 3 graphs which have the same x.axis underneath each other. i'd
like the plots to be aligned without margings between the boxes and draw a
single x axis beneath the lowest plot.

i managed to get the alignment by setting par(mar), but the middle box is
stretched 
and i cant't figure out how to get around this. par(pin) was my guess, but
this doesn't do the job because it seems to be overridden by par(mar).

sorry for the long example data, but this was quick at hand..

mydata:
###################################################################
ad<-data.frame(
list(structure(list(pos = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L), .Label = c("Gaps", "Surroundings"), class = "factor"), 
    stage = structure(c(4L, 2L, 3L, 1L, 4L, 2L, 3L, 1L), .Label =
c("Alpine_Grassl.", 
    "Early", "Late", "Pioneer"), class = "factor"), mw = c(12.06293707, 
    26.09265735, 37.12287713, 81.53846154, 28.88005449, 68.44004261, 
    97.61124961, 100)), .Names = c("pos", "stage", "mw"), class =
"data.frame", row.names = c(NA, 
-8L))))

seedl<-data.frame(
list(structure(list(pos = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L), .Label = c("Gaps", "Surroundings"), class = "factor"), 
    stage = structure(c(4L, 2L, 3L, 1L, 4L, 2L, 3L, 1L), .Label =
c("Alpine_Grassl.", 
    "Early", "Late", "Pioneer"), class = "factor"), mw = c(24.52797203, 
    17.20571096, 41.68401043, 34.03846154, 13.92056379, 9.955734802, 
    23.54039945, 26.11543325)), .Names = c("pos", "stage", "mw"
), class = "data.frame", row.names = c(NA, -8L))))

rich<-data.frame(
list(structure(list(pos = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L), .Label = c("Gaps", "Surroundings"), class = "factor"), 
    stage = structure(c(4L, 2L, 3L, 1L, 4L, 2L, 3L, 1L), .Label =
c("Alp._Grassl.", 
    "Early", "Late", "Pioneer"), class = "factor"), n = c(44L, 
    44L, 45L, 10L, 44L, 44L, 45L, 10L), mw = c(1.93, 3.59, 4.24, 
    6.8, 1.84, 5.61, 7.2, 10.6)), .Names = c("pos", "stage", 
"n", "mw"), class = "data.frame", row.names = c(NA, -8L))))
###################################################################
windows(5,15)
par(ps=8,mgp=c(2.25,1,0),mfrow=c(3,1))
###################################################################
par(mar=c(0,4,4,2))

attach(seedl)
plot(c(1:4),mw[1:4],type="o",xaxt="n",xlab="",
     ylab="Abundance
(%)",ylim=c(0,100),xlim=c(0.7,4.3),pch=22,bg="white",cex=0.75,las=1)
par(new=T)
plot(c(1:4),mw[5:8],type="o",xaxt="n",xlab="",yaxt="n",
     ylab="",ylim=c(0,100),xlim=c(0.7,4.3),pch=15,cex=0.75)
text(0.7,90,adj=0,"Seedlings",font=2)
legend("topright",c("Surr.","Gaps"),bty="n",pch=c(15,0))

###################################################################
par(ps=8,mgp=c(2.25,1,0),mar=c(0,4,0,2))

attach(ad)
plot(c(1:4),mw[1:4],type="o",xaxt="n",xlab="",
     ylab="Abundance
(%)",ylim=c(0,100),xlim=c(0.7,4.3),pch=22,bg="white",cex=0.75,las=1)
par(new=T)
plot(c(1:4),mw[5:8],type="o",xaxt="n",xlab="",yaxt="n",
     ylab="",ylim=c(0,100),xlim=c(0.7,4.3),pch=15,cex=0.75)

text(0.7,90,adj=0,"Adults",font=2)
###################################################################
par(ps=8,mgp=c(2.25,1,0),mar=c(4,4,0,2))

attach(rich)
plot(c(1:4),mw[1:4],type="o",xaxt="n",xlab="",
     ylab="Abundance
(%)",ylim=c(0,12),xlim=c(0.7,4.3),pch=22,bg="white",cex=0.75,las=1)
par(new=T)
plot(c(1:4),mw[5:8],type="o",xaxt="n",xlab="",yaxt="n",
     ylab="",ylim=c(0,12),xlim=c(0.7,4.3),pch=15,cex=0.75)
axis(1,at=c(1:4),labels=c(rep("",4)))
axis(1,at=c(1:4),line=1.2,lwd=0,adj=0,hadj=0.5,padj=0.5,las=2,
     labels=c("Pioneer","Early","Late","Alpine\nGrassland"))
text(0.7,11,adj=0,"Richness",font=2)
###################################################################
dev.off()
-- 
View this message in context: http://n4.nabble.com/multiple-plots-problem-tp2017326p2017326.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list