How to change panel stickers and x-axis sublayers in the bwplot grid

I need 2 weeks to use RStudio (MacOS), so please forgive me if I missed an obvious function that would solve my problem.
As a project, I am trying to reproduce a cell graph with four graphs representing Net Benefit, provided that the disease type is “not severe” (0) or “serious” (1) as the x-axis label and this treatment is “speech therapy” (0) or “drug therapy” (1) as a marking of the x axis.

Here is my script:

tx <- c(0,0,0,0,1,1,1,1) dztype <- c(1,0,1,0,0,0,1,1) NBwtp1000 <- c(-5500,-4000,-5000,-1000,-5000,-5000,-2800,-2000) require(lattice) bwplot(NBwtp1000 ~ paste0("Tx ", tx) | paste0("Disease Severity ", dztype), xlab="Talk Therapy (Tx 0) or Drug Therapy (Tx 1)", ylab="Net Benefit @ wtp 1000", horizontal=FALSE) 

If you run the code, you'll see a box-and-whisker graph: I'm almost there, thanks to some informative posts on this forum about the bwplot lattice bwplot .

However, I am still not happy with the result. I used the paste0 function to add line descriptors to the X axis paste0 for the treatment group (originally labeled “1,2” and now showing as “Tx 0, Tx 1”), but I would ideally want these sublayers to say “Talk Therapy” and "Drug Therapy", respectively. (I just did not know how to do away with existing numerical labels.)
Likewise, I would like the panel labels to say “Not Severe,” where the label is currently 0 and “Severe,” where the label is currently 1.

+7
source share
1 answer

The easiest way, as far as I see, is to convert your tx and dztype into factors with the corresponding level names.

 tx <- factor(tx, levels=c(0,1), labels=c("Talk Therapy", "Drug Therapy")) dztype <- factor(dztype, levels=c(0,1), labels=c("Not severe", "Severe")) bwplot(NBwtp1000 ~ tx | dztype, xlab="Talk Therapy or Drug Therapy", ylab="Net Benefit @ wtp 1000", horizontal=FALSE) 

enter image description here

Another solution is to use the scale argument for tx levels and the strip argument for dztype :

 tx <- c(0,0,0,0,1,1,1,1) dztype <- c(1,0,1,0,0,0,1,1) bwplot(NBwtp1000 ~ tx | dztype, xlab="Talk Therapy or Drug Therapy", ylab="Net Benefit @ wtp 1000", horizontal=FALSE, scales=list(x=list(labels=c("Talk therapy","Drug Therapy"))), strip=strip.custom(var.name="Disease severity", factor.levels=c(" Not Severe", "Severe"), strip.levels=rep(TRUE,2))) 

enter image description here

+6
source

All Articles