Dear all, I am plotting the count of some data subdivided in different groups. the variables i am using are: A = tests performed B = positive/negative results (but in this case the results are all positive, so all 1) C = multiple (1) or single (0) test applied D = count of instances E = cases (1) or controls (0) the plot looks the way I need and it is created with lattice's barchart. However the strip should indicate "cases"/"controls" and instead only shows "E"/"E" so I think I messed somewhere. Would you know what did I missed? 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")) ), strip = strip.custom(factor.levels = c("Cases","Controls"), par.strip.text = list(cex = 1) ) )
David Winsemius
2015-Dec-18 21:18 UTC
[R] lattice strip.custom in plot for multiple groups
> On Dec 18, 2015, at 12:22 PM, Luigi Marongiu <marongiu.luigi at gmail.com> wrote: > > Dear all, > I am plotting the count of some data subdivided in different groups. > the variables i am using are: > A = tests performed > B = positive/negative results (but in this case the results are all > positive, so all 1) > C = multiple (1) or single (0) test applied > D = count of instances > E = cases (1) or controls (0) > > the plot looks the way I need and it is created with lattice's > barchart. However the strip should indicate "cases"/"controls" and > instead only shows "E"/"E" so I think I messed somewhere. > Would you know what did I missed? > 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")) > ), > strip = strip.custom(factor.levels = c("Cases","Controls"),Also need to set the logical flag strip.levels to TRUE. strip = strip.custom(factor.levels = c("Cases","Controls"), strip.levels=TRUE, par.strip.text = list(cex = 1) If you do not want the variable name "E" displayed then set the correct flag to FALSE. See: ?strip.custom -- David> par.strip.text = list(cex = 1) > ) > ) > > ______________________________________________ > 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