Sylvia Rodriguez
Sylvia Rodriguez

Reputation: 1353

Modify facet labels using ggpubr package in R

I am using the ggscatter function in the ggpubr package in R. See following code using the ToothGrowth dataset as an example:

library("ggpubr")
ggscatter(ToothGrowth, x = "dose", y = "len",
  color = "supp", facet.by = "supp")

I would like to add the sample sizes (n) to the facet labels, so that they read: "OJ (n=30)" and "VC (n=30)". I assume that I need to use "panel.labs". Instructions say:

panel.labs = list(sex = c("Male", "Female"), rx = c("Obs", "Lev", "Lev2")

But I am not able to modify this to get where I hope to get. It also was not clear what "rx" means. Any suggestions would be terrific. Thank you.

Edit

Thanks for your answers below. I would like to clarify that I would like to include the "n=30" in the code, so that the '30' is automatically added from the data, not just as a text label saying 'n=30'. I need to do this at a larger scale, on which it is not possible to add each individually as text. Apologies for not being clearer in my initial question. Thank you.

Upvotes: 0

Views: 1483

Answers (1)

IRTFM
IRTFM

Reputation: 263411

This worked for me (as an argument to ggscatter). It needs to have the variable name that hold the factor variable name and then it need to have the items in the proper order, in this case the OJ label first:

panel.labs = list( supp=c( "OJ (n=30)" , "VC (n=30)") ) )

enter image description here

Upvotes: 1

Related Questions