1

I want to have cleaner names for the Y axes in my stratified graph below

Eg: Gender variable called "gender2", has two levels "Male", "Female". Upon plotting,

AGsex=Recur(exityrs,id,as.integer(anyhpv))~gender2
plotEvents(AGsex,xlab="Time in years",base_size=5,)

i get Recur object of subjects followup trajectories in study, with a reccurent event marked by a green dot I would like the stratified y axes to say "Male" and "female" only..would this be a feature of the plot function? I.e is there a easy way of doing this in the plot code itself instead of having to create temporary data frames etc

  • 1
    what package is this? can you share sample data? – r2evans Aug 09 '23 at 16:04
  • I am using the Recur and reda packages, teh data structure is longitudinal where each participant can have multiple rows, one row per event, where the final row is time from last event observed until censor. – Sakshi Tewari Aug 09 '23 at 16:50
  • There is no `Recur` package on CRAN. Do you mean you're using `reda::Recur()`? – r2evans Aug 09 '23 at 17:06
  • 1
    Please make this question *reproducible*. This includes listing all non-base packages (I think it's just `reda` here), sample *unambiguous* data (e.g., `data.frame(x=...,y=...)` or the output from `dput(head(x))` into a [code block]), and intended output given that input. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Aug 09 '23 at 17:07

1 Answers1

0

This functionality seems to be hard coded into the plotEvents() function so I don't think there's a built-in option for this. However, since it returns a ggplot object, you can modify the facetting layer and edit the labels:

# minimal example
library(reda)
library(reReg)
gender2 <- rep(c("Male", "Female"), 5)
ex1 <- Recur(1:10)~gender2
g = plotEvents(ex1) 

# function to remove the gender2 part of the label from a string
rm_label <- function(string, to_rm = "gender2 = ") {
  string <- stringr::str_remove(string, to_rm)
  string
}

# remake the plot and add your own facets
g + 
  facet_wrap(~gender2, ncol = 1, strip.position = "left",
             labeller = labeller(gender2 = rm_label))

gives:

plot

nrennie
  • 1,877
  • 1
  • 4
  • 14