0

I was working in lattice/densityplot and want to change the "in", "out" sub-titles to "inpatinet", "outpatient". Thank you. The image and code below:

colors = c("black", "blue")
lines = c(1,2) #1
points = c(16,17)
key.trans <- list(title="Gender",
                  corner = c(0.90, 0.90),
                  #space="bottom", columns=2, #2
                  text=list(c("Female","Male")),
                  #points=list(pch=points, col=colors),
                  lines=list(col=colors, lty=lines),
                  cex.title=1, cex=.9) 

densityplot(~ Age_yrs|Location_type, groups=Sex,  
            data = subset(all_isolates_inc_ATCC, Age_yrs<100 & 
                   Institution=="P06" 
                   & Organism=="eco" 
                   & Location_type!="unk"), 
            xlab = "Age, years",
            lty=lines, col=colors,
            lwd=2, 
            plot.points = FALSE,
            #jitter=.00005,
            key=key.trans)

enter image description here

Aybek Khodiev
  • 596
  • 1
  • 4
  • 10
  • in generall the density plot takes the names of your groups. Is it a solution for you, when you change the names of `in` and `out` of your dataframe before plotting? Also you could provide your data with `dput` to make this question easier to answer – mischva11 Apr 24 '19 at 11:02
  • Yes, it is clear, but I thought there might be an elegant way to change the titles without changing the data. Thank you. – Aybek Khodiev Apr 24 '19 at 11:03

1 Answers1

1

The strip names can be changed in the function with the strip.custom function. A related question was asked in Change text on strips in lattice plots. In your case you would add the following argument to your densityplot() call:

   strip = strip.custom(factor.levels = c("In patient", "Out patient"))

More information is found with help for strip.default although help for strip.custom gets you there as well.

David O
  • 803
  • 4
  • 10
  • Thank you for your reply. I changed the data in the data frame to address it quickly, though will dig the strip function. – Aybek Khodiev May 20 '19 at 11:36
  • Glad to hear. One benefit of this approach is you can replace short or cryptic factor labels ith more user friendly text, even `expressions`. – David O May 20 '19 at 12:37