[R] Retaining X axis labels when combining lattice graphs
Duncan Mackay
mackay at northnet.com.au
Thu Oct 18 03:14:41 CEST 2012
Hi
I am not sure what you want but this works.
dput(PCB.hab.dist.paramaters.sub, "clipboard")
structure(list(a0 = c(0.04914389, 0.09828646, 0.14743004, 0.19650279,
0.24562863, 0.29475427, 0.34321628, 0.39224708, 0.4396493, 0.48849916,
0.04822307, 0.09644467, 0.14466705, 0.19265015, 0.24081446, 0.28897841,
0.33559511, 0.38114791, 0.4287918, 0.47643549, 0.04780828, 0.09551991,
0.14323731, 0.19111263, 0.23918126, 0.2870228, 0.33432429, 0.38066666,
0.42687761, 0.47430651, 0.04692786, 0.09382041, 0.1407303, 0.18771848,
0.23465733, 0.28160051, 0.3273384, 0.37086396, 0.41724004, 0.46361589
), b0 = c(-0.86892828, -0.86809873, -0.86819141, -0.87080033,
-0.87083379, -0.87079976, -0.88677178, -0.88675509, -0.91339697,
-0.91338693, 0.01662903, 0.01777045, 0.01821094, 0.01109928,
0.01112177, 0.01117924, -0.01359166, -0.04000038, -0.04000463,
-0.0400053, 0.22108929, 0.22315344, 0.22140675, 0.21089745, 0.2225532,
0.2227686, 0.20244, 0.1771299, 0.15966148, 0.15952135, 0.68334412,
0.69342727, 0.69065706, 0.68153656, 0.68206868, 0.68258821, 0.64959219,
0.6037267, 0.6041549, 0.60449739), c0 = c(0.0003944847, 0.0003945627,
0.0003945485, 0.000464031, 0.0004640277, 0.0004640311, 0.0005741337,
0.0005741361, 0.0007836726, 0.0007836736, 0.0004875154, 0.0004877006,
0.0004877409, 0.0005715912, 0.0005715677, 0.000571565, 0.0007090505,
0.0009754073, 0.0009754005, 0.000975399, 0.0004442073, 0.0003972545,
0.0003926791, 0.0005427425, 0.0004810829, 0.0004810596, 0.000580295,
0.0006780412, 0.0007653099, 0.0007652945, 0.0005052207, 0.000493725,
0.0005042077, 0.0005905591, 0.0005905449, 0.0005905167, 0.0006951437,
0.0008839044, 0.0008837397, 0.0008836109), Index = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "PCB", class = "factor"),
Distribution = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L), .Label = c("2 Patches", "4 Patches", "5 Patches",
"9 Patches"), class = "factor"), REP = c(1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), Habitat.Amt = c(5L, 10L,
15L, 20L, 25L, 30L, 35L, 40L, 45L, 50L, 5L, 10L, 15L, 20L,
25L, 30L, 35L, 40L, 45L, 50L, 5L, 10L, 15L, 20L, 25L, 30L,
35L, 40L, 45L, 50L, 5L, 10L, 15L, 20L, 25L, 30L, 35L, 40L,
45L, 50L), Patches = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L)), .Names = c("a0", "b0", "c0", "Index", "Distribution",
"REP", "Habitat.Amt", "Patches"), class = "data.frame", row.names = c(NA,
-40L))
##habitat amount graph
a0.Habitat<-
bwplot(Habitat.Amt~a0, data =PCB.hab.dist.paramaters.sub,
par.settings = list(plot.symbol = list(pch = 2, col = "black"),
col=1,
box.umbrella=list(lty=1, col="black"),
box.rectangle=list(lty=1, col="black")),
ylab=list("Asymptote (a)",cex=1.5),
xlab=list("Habitat Amount (% of Landscape)", cex=1.5))
##patch graph
a0.Patches<-
bwplot(Patches~a0, data =PCB.hab.dist.paramaters.sub,
par.settings = list(plot.symbol = list(pch = 2, col = "black"),
col=1,
box.umbrella=list(lty=1, col="black"),
box.rectangle=list(lty=1, col="black")),
# horizontal = F,
ylab=list("Asymptote (a)",cex=1.5),
xlab=list("Number of Habitat Patches", cex=1.5))
####combine two graphs
combined.a0<-c( "Response_to_Fragmentation"=a0.Patches,
"Response_to_Habitat_Amount"=a0.Habitat, layout=c(1,2), x.same=FALSE)
###update
update(combined.a0, main="TL Landscape",
scales=list(y=list(alternating=FALSE),x=list(alternating=TRUE )))
This gives you bwplots as the lattice function formula you had only
produced points.
Please in future use dput. for your data as it took extra time to
work out what was going on.
I am not sure what you want as I could not get the bwplots first up.
This may help you
You may have to specify axis limits but it is a while since I have
done something like this.
Not sure if ? trellis.focus is a help
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
At 05:54 18/10/2012, you wrote:
>I am attempting to create a plot that includes boxplots of the response of a
>variable (a0) to changes in two factors as two vertical panels (data set
>pasted at end and included as attachment, though should not be necessary).
>I am able to combine the two plots using the c.trellis function in
>latticeExtra, which I then update to include a title and any other desired
>changes, but cannot determine how to include a label for the x axis in the
>top plot.
>
>##habitat amount graph
>a0.Habitat<-bwplot(a0~Habitat.Amt, data =PCB.hab.dist.paramaters.sub,
> par.settings = list(plot.symbol = list(pch = 2, col =
>"black"),col=1,box.umbrella=list(lty=1, col="black"),
> box.rectangle=list(lty=1, col="black")),
> ylab=list("Asymptote (a)",cex=1.5),
> xlab=list("Habitat Amount (% of Landscape)", cex=1.5))
>
>##patch graph
>a0.Patches<-bwplot(a0~Patches, data =PCB.hab.dist.paramaters.sub,
> par.settings = list(plot.symbol = list(pch = 2, col =
>"black"),col=1,box.umbrella=list(lty=1, col="black"),
> box.rectangle=list(lty=1, col="black")),
> ylab=list("Asymptote (a)",cex=1.5),
> xlab=list("Number of Habitat Patches", cex=1.5))
>
>####combine two graphs
>combined.a0<-c( "Response_to_Fragmentation"=a0.Patches,
>"Response_to_Habitat_Amount"=a0.Habitat, layout=c(1,2), x.same=FALSE)
>
>###update
>update(combined.a0, main="TL Landscape",
>scales=list(y=list(alternating=FALSE),x=list(alternating=TRUE )))
>
>This feels like it shoull have a really simple answer but I have been unable
>to find any solutions on this or other R help forums to this problem. I have
>attempted to not define the xlab when the initial plots are drawn and
>specify it at the update step, but this leads to the labels being spread
>across the bottom, I assume since the Update funtion is working on the plot
>object as a single panel. Using xlab.top to put the lable above the upper
>graph looks odd.
>
>###attempt to specify 2 labels with xlab
>update(combined.a0, main="TL Landscape",
>scales=list(y=list(alternating=FALSE),x=list(alternating=TRUE) ),
>xlab=c("Habitat Amount (% of Landscape)", "Patches"))
>
>
> There are plenty of discussion regarding how to manipulate the scale that
>axis are drawn at, which is how I arrived at combining plots using
>latticeExtra as opposed to drawing the two plots together with the extended
>lattice interface which had somw quiriky behaviour in ordering factor levels
>across the x axis.
>
>bwplot(a0~(Patches)+(Habitat.Amt), outer=TRUE,
>data=PCB.hab.dist.paramaters.sub,
> par.settings = list(plot.symbol = list(pch = 2, col = "black"),col=1,
> box.umbrella=list(lty=1, col="black"),box.rectangle=list(lty=1,
>col="black")),
> ylab=list("Asymptote (a)",cex=1.5),
> xlab=c("Hab", "Patches"), layout=c(1,2),scales=list(relation="free" ))
>
>Any help would how I could either specify for the Xaxis labels of both
>graphs to be included when combined, or ways to specify seperate axis labels
>after combination would be extremely helpful.
>Thanks for your time.
>
>
> a0 b0 c0 Index Distribution REP Habitat.Amt
>Patches
>1 0.04914389 -0.86892828 0.0003944847 PCB 2
>Patches 1 5
>2
>2 0.09828646 -0.86809873 0.0003945627 PCB 2
>Patches 2 10
>2
>3 0.14743004 -0.86819141 0.0003945485 PCB 2
>Patches 3 15
>2
>4 0.19650279 -0.87080033 0.0004640310 PCB 2
>Patches 4 20
>2
>5 0.24562863 -0.87083379 0.0004640277 PCB 2
>Patches 5 25
>2
>6 0.29475427 -0.87079976 0.0004640311 PCB 2
>Patches 6 30
>2
>7 0.34321628 -0.88677178 0.0005741337 PCB 2
>Patches 7 35
>2
>8 0.39224708 -0.88675509 0.0005741361 PCB 2
>Patches 8 40
>2
>9 0.43964930 -0.91339697 0.0007836726 PCB 2
>Patches 9 45
>2
>10 0.48849916 -0.91338693 0.0007836736 PCB 2
>Patches 10 50
>2
>16 0.04822307 0.01662903 0.0004875154 PCB 4
>Patches 1 5
>4
>17 0.09644467 0.01777045 0.0004877006 PCB 4
>Patches 2 10
>4
>18 0.14466705 0.01821094 0.0004877409 PCB 4
>Patches 3 15
>4
>19 0.19265015 0.01109928 0.0005715912 PCB 4
>Patches 4 20
>4
>20 0.24081446 0.01112177 0.0005715677 PCB 4
>Patches 5 25
>4
>21 0.28897841 0.01117924 0.0005715650 PCB 4
>Patches 6 30
>4
>22 0.33559511 -0.01359166 0.0007090505 PCB 4
>Patches 7 35
>4
>23 0.38114791 -0.04000038 0.0009754073 PCB 4
>Patches 8 40
>4
>24 0.42879180 -0.04000463 0.0009754005 PCB 4
>Patches 9 45
>4
>25 0.47643549 -0.04000530 0.0009753990 PCB 4
>Patches 10 50
>4
>31 0.04780828 0.22108929 0.0004442073 PCB 5
>Patches 1 5
>5
>32 0.09551991 0.22315344 0.0003972545 PCB 5
>Patches 2 10
>5
>33 0.14323731 0.22140675 0.0003926791 PCB 5
>Patches 3 15
>5
>34 0.19111263 0.21089745 0.0005427425 PCB 5
>Patches 4 20
>5
>35 0.23918126 0.22255320 0.0004810829 PCB 5
>Patches 5 25
>5
>36 0.28702280 0.22276860 0.0004810596 PCB 5
>Patches 6 30
>5
>37 0.33432429 0.20244000 0.0005802950 PCB 5
>Patches 7 35
>5
>38 0.38066666 0.17712990 0.0006780412 PCB 5
>Patches 8 40
>5
>39 0.42687761 0.15966148 0.0007653099 PCB 5
>Patches 9 45
>5
>40 0.47430651 0.15952135 0.0007652945 PCB 5
>Patches 10 50
>5
>46 0.04692786 0.68334412 0.0005052207 PCB 9
>Patches 1 5
>9
>47 0.09382041 0.69342727 0.0004937250 PCB 9
>Patches 2 10
>9
>48 0.14073030 0.69065706 0.0005042077 PCB 9
>Patches 3 15
>9
>49 0.18771848 0.68153656 0.0005905591 PCB 9
>Patches 4 20
>9
>50 0.23465733 0.68206868 0.0005905449 PCB 9
>Patches 5 25
>9
>51 0.28160051 0.68258821 0.0005905167 PCB 9
>Patches 6 30
>9
>52 0.32733840 0.64959219 0.0006951437 PCB 9
>Patches 7 35
>9
>53 0.37086396 0.60372670 0.0008839044 PCB 9
>Patches 8 40
>9
>54 0.41724004 0.60415490 0.0008837397 PCB 9
>Patches 9 45
>9
>55 0.46361589 0.60449739 0.0008836109 PCB 9
>Patches 10 50
>9 PCB_hab_dist_paramaters_sub.txt
><http://r.789695.n4.nabble.com/file/n4646514/PCB_hab_dist_paramaters_sub.txt>
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Retaining-X-axis-labels-when-combining-lattice-graphs-tp4646514.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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