Dear all, I am plotting some data using lattice's barchart. One of the counts I am plotting has a very large value with respect to the other variables and I would like to introduce a break in the axis to compensate for this 'anomaly' and give more breath to the other bars. In this example the high count is for the variable 'b' and I would like to introduce a break of 50-100 in the x axis. I have seen from the internet that the common approach is to stack together two figures but in my case I am using a multipanel plot and I think this way won't work for my plot. Is there a simple way to introduce a break in the axis of a multipanel lattice plot? Thank you L the example:>>>A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'd') B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, 1, 5, 0, 0) E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1) DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE) library(lattice) barchart( A ~ D|E, DF, groups = C, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "orange"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "orange")) ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Single infections", "Multiple infections"), col="black"), rectangles=list(col=c("yellow", "orange")) ), )
Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Dec 18, 2015 at 12:32 PM, Luigi Marongiu <marongiu.luigi at gmail.com> wrote:> Dear all, > I am plotting some data using lattice's barchart. One of the counts I > am plotting has a very large value with respect to the other variables > and I would like to introduce a break in the axis to compensate for > this 'anomaly' and give more breath to the other bars. In this example > the high count is for the variable 'b' and I would like to introduce a > break of 50-100 in the x axis. > I have seen from the internet that the common approach is to stack > together two figures but in my case I am using a multipanel plot and I > think this way won't work for my plot. > Is there a simple way to introduce a break in the axis of a multipanel > lattice plot?No. (Thank goodness -- it defeats the purpose of the display). -- Bert> Thank you > L > > the example: >>>> > A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', > 'b', 'c', 'd', 'b', 'c', 'd') > B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1) > C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, > 1, 1, 1) > D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, > 1, 5, 0, 0) > E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, > 1, 1, 1) > DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE) > library(lattice) > barchart( > A ~ D|E, > DF, > groups = C, > stack = TRUE, > main = "Comparison of test results", > xlab = "Count", > col = c("yellow", "orange"), > par.settings = list( > strip.background = list(col="light grey"), > superpose.polygon=list(col= c("yellow", "orange")) > ), > scales = list( > alternating = FALSE > ), > key = list( > space="top", > columns=2, > text=list(c("Single infections", "Multiple infections"), col="black"), > rectangles=list(col=c("yellow", "orange")) > ), > ) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
> On Dec 18, 2015, at 12:32 PM, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: > > Dear all, > I am plotting some data using lattice's barchart. One of the counts I > am plotting has a very large value with respect to the other variables > and I would like to introduce a break in the axis to compensate for > this 'anomaly' and give more breath to the other bars. In this example > the high count is for the variable 'b' and I would like to introduce a > break of 50-100 in the x axis. > I have seen from the internet that the common approach is to stack > together two figures but in my case I am using a multipanel plot and I > think this way won't work for my plot. > Is there a simple way to introduce a break in the axis of a multipanel > lattice plot?If there is, then it's not easy to find. I tried with `sos::findFn("axis break lattice")`. There are base graphic broken axes offered in package:plotrix. If you are sticking with lattice, then I would suggest a logged y-axis. Or use an annotating up-arrow with a label where the ylim was restricted. -- David.> Thank you > L > > the example: >>>> > A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', > 'b', 'c', 'd', 'b', 'c', 'd') > B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 1, 1) > C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, > 1, 1, 1) > D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, > 1, 5, 0, 0) > E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, > 1, 1, 1) > DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE) > library(lattice) > barchart( > A ~ D|E, > DF, > groups = C, > stack = TRUE, > main = "Comparison of test results", > xlab = "Count", > col = c("yellow", "orange"), > par.settings = list( > strip.background = list(col="light grey"), > superpose.polygon=list(col= c("yellow", "orange")) > ), > scales = list( > alternating = FALSE > ), > key = list( > space="top", > columns=2, > text=list(c("Single infections", "Multiple infections"), col="black"), > rectangles=list(col=c("yellow", "orange")) > ), > ) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.David Winsemius Alameda, CA, USA
Hi Luigi I suppose a cheats way out would be to put scales = list(alternating = FALSE, x = list(relation = "free") ), Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi Marongiu Sent: Saturday, 19 December 2015 06:32 To: r-help Subject: [R] introduce axis break lattice plot multipanel Dear all, I am plotting some data using lattice's barchart. One of the counts I am plotting has a very large value with respect to the other variables and I would like to introduce a break in the axis to compensate for this 'anomaly' and give more breath to the other bars. In this example the high count is for the variable 'b' and I would like to introduce a break of 50-100 in the x axis. I have seen from the internet that the common approach is to stack together two figures but in my case I am using a multipanel plot and I think this way won't work for my plot. Is there a simple way to introduce a break in the axis of a multipanel lattice plot? Thank you L the example:>>>A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'd') B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, 1, 5, 0, 0) E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1) DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE) library(lattice) barchart( A ~ D|E, DF, groups = C, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "orange"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "orange")) ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Single infections", "Multiple infections"), col="black"), rectangles=list(col=c("yellow", "orange")) ), ) ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Hi Luigi If you went down the relation = ?free? road you could change the panel widths to reflect the scales eg if lhs was 1:200 and rhs was 1:100 then the lhs panel would be twice as wide as the rhs. I have some code reasonably handy I could send it to you if needed. Regards Duncan From: Luigi Marongiu [mailto:marongiu.luigi at gmail.com] Sent: Sunday, 20 December 2015 20:35 To: Duncan Mackay Subject: RE: [R] introduce axis break lattice plot multipanel thank you duncan, but in that case the scale of the two panel would be different. i think ill keep it as it comes. best wishes of a merry xmas luigi On 19 Dec 2015 13:42, "Duncan Mackay" <dulcalma at bigpond.com> wrote: Hi Luigi I suppose a cheats way out would be to put scales = list(alternating = FALSE, x = list(relation = "free") ), Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mackay at northnet.com.au -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi Marongiu Sent: Saturday, 19 December 2015 06:32 To: r-help Subject: [R] introduce axis break lattice plot multipanel Dear all, I am plotting some data using lattice's barchart. One of the counts I am plotting has a very large value with respect to the other variables and I would like to introduce a break in the axis to compensate for this 'anomaly' and give more breath to the other bars. In this example the high count is for the variable 'b' and I would like to introduce a break of 50-100 in the x axis. I have seen from the internet that the common approach is to stack together two figures but in my case I am using a multipanel plot and I think this way won't work for my plot. Is there a simple way to introduce a break in the axis of a multipanel lattice plot? Thank you L the example:>>>A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'd') B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, 1, 5, 0, 0) E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1) DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE) library(lattice) barchart( A ~ D|E, DF, groups = C, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "orange"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "orange")) ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Single infections", "Multiple infections"), col="black"), rectangles=list(col=c("yellow", "orange")) ), ) ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]]