[R] modify strip labels with given text using lattice package
Dear all, I am drawing a barchart plot with lattice and the resulting strips are taking the value of the variable being compared (in this example "assay"). However I would like to write myself the value to place into the strips, let's say I want to call the variables as "molecular test" and "serological test" the values "a" and "b" respectively within "assay". I have tried different approaches taken from the web but nothing worked. Would you have any tip? Best regards Luigi >>> test <- rep(c("Adenovirus", "Rotavirus", "Norovirus", "Rotarix", "Sapovirus"), 2) res <- c(0, 1, 0, 1,0, 1,0, 1,0, 1, 0, 1, 0, 1,0, 1,0, 1,0, 1) count <- rnorm(20) assay <- c(rep("a", 10), rep("b", 10)) df <- data.frame(test, res, count, assay, stringsAsFactors = FALSE) library(lattice) barchart( test ~ count|assay, df, groups = res, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "blue"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "blue")) ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Negative", "Positive"), col="black"), rectangles=list(col=c("yellow", "blue")) ) ) __ R-help@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.
Re: [R] modify strip labels with given text using lattice package
On Aug 31, 2015, at 1:17 PM, Luigi Marongiu wrote: > Dear all, > I am drawing a barchart plot with lattice and the resulting strips are > taking the value of the variable being compared (in this example > "assay"). However I would like to write myself the value to place into > the strips, let's say I want to call the variables as "molecular test" > and "serological test" the values "a" and "b" respectively within > "assay". I have tried different approaches taken from the web but > nothing worked. Look at ?barchart in the section on arguments to strip and then at ?strip.default for how to use `strip.custom`. If you needed finer control there are functions that return the panel, but this request did not require using it: barchart( test ~ count|assay, df, groups = res, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "blue"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "blue")) ), strip = strip.custom( factor.levels=c("molecular test","serological test") ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Negative", "Positive"), col="black"), rectangles=list(col=c("yellow", "blue")) ) ) > Would you have any tip? > Best regards > Luigi > > test <- rep(c("Adenovirus", "Rotavirus", "Norovirus", "Rotarix", > "Sapovirus"), 2) > res <- c(0, 1, 0, 1,0, 1,0, 1,0, 1, 0, 1, 0, 1,0, 1,0, 1,0, 1) > count <- rnorm(20) > assay <- c(rep("a", 10), rep("b", 10)) > > df <- data.frame(test, res, count, assay, stringsAsFactors = FALSE) > > library(lattice) > barchart( >test ~ count|assay, >df, >groups = res, >stack = TRUE, >main = "Comparison of test results", >xlab = "Count", >col = c("yellow", "blue"), >par.settings = list( >strip.background = list(col="light grey"), >superpose.polygon=list(col= c("yellow", "blue")) >), >scales = list( >alternating = FALSE >), >key = list( >space="top", >columns=2, >text=list(c("Negative", "Positive"), col="black"), >rectangles=list(col=c("yellow", "blue")) >) > ) > > __ > R-help@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 __ R-help@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.
Re: [R] modify strip labels with given text using lattice package
Hi Luigi add strip.custom argument barchart(test ~ count|assay, df, groups = res, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "blue"), strip= strip.custom(factor.levels = c("molecular test","serological test"), par.strip.text = list(cex = 1) ), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "blue")) ), scales = list(alternating = FALSE), key = list( space="top", columns=2, text=list(c("Negative", "Positive"), col="black"), rectangles=list(col=c("yellow", "blue")) ) ) -Original Message----- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi Marongiu Sent: Tuesday, 1 September 2015 06:18 To: r-help Subject: [R] modify strip labels with given text using lattice package Dear all, I am drawing a barchart plot with lattice and the resulting strips are taking the value of the variable being compared (in this example "assay"). However I would like to write myself the value to place into the strips, let's say I want to call the variables as "molecular test" and "serological test" the values "a" and "b" respectively within "assay". I have tried different approaches taken from the web but nothing worked. Would you have any tip? Best regards Luigi >>> test <- rep(c("Adenovirus", "Rotavirus", "Norovirus", "Rotarix", "Sapovirus"), 2) res <- c(0, 1, 0, 1,0, 1,0, 1,0, 1, 0, 1, 0, 1,0, 1,0, 1,0, 1) count <- rnorm(20) assay <- c(rep("a", 10), rep("b", 10)) df <- data.frame(test, res, count, assay, stringsAsFactors = FALSE) library(lattice) barchart( test ~ count|assay, df, groups = res, stack = TRUE, main = "Comparison of test results", xlab = "Count", col = c("yellow", "blue"), par.settings = list( strip.background = list(col="light grey"), superpose.polygon=list(col= c("yellow", "blue")) ), scales = list( alternating = FALSE ), key = list( space="top", columns=2, text=list(c("Negative", "Positive"), col="black"), rectangles=list(col=c("yellow", "blue")) ) ) __ R-help@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. __ R-help@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.