At present, the new 2.8 version of the ggrcs package written by me has been launched on CRAN, and currently supports logistic regression (logistic regression), cox regression and multiple linear regression. Version 2.8 has further processed the details of the double-group drawing, and added the function of modifying the label. And introduce how to modify the font on the ggrcs package.
You can use the code to install if you need it
install.packages("ggrcs")
If the old version is installed, you can upgrade it through Rstudio
so that you can upgrade to the latest version. I will not introduce the new version and the previous functions. The
new function corrects some details of double-group variable drawing, and adds modification of variable names. Tag of. I'll come one by one.
First import the R package and data, here use the smoking data that comes with the R package
library(rms)
library(ggplot2)
library(scales)
library(ggrcs)
dt<-smoke
dd<-datadist(dt)
options(datadist='dd')
fit<- cph(Surv(time,status==1) ~ rcs(age,4)+gender, x=TRUE, y=TRUE,data=dt)
Draw a double-group variable curve graph. In the past, the picture generated by drawing the double-group variable is
I will draw it again after the revision, and the picture is more delicate
ggrcs(data=dt,fit=fit,x="age",group="gender")
The quality of the picture is significantly higher than the original. Some netizens asked if the label of the group on the left can be modified? After the revision, the function of modifying labels has been added.
ggrcs(data=dt,fit=fit,x="age",group="gender",twotag.name=(c("female","male")))
In addition, the function of modifying the border color has also been added to make your graphics more personalized. Here we change it to a yellow border
ggrcs(data=dt,fit=fit,x="age",group="gender",twotag.name=(c("female","male")),bordercol="yellow")
Finally, some netizens asked if the font size can be changed? Can the font be changed to New Roman? The ggrcs package is fully connected to ggplot2, and changing the font is too simple.
Set it as a picture first
p<-ggrcs(data=dt,fit=fit,x="age",group="gender",twotag.name=(c("female","male")),bordercol="yellow")
It is completely a modified method of ggplot. You can control the size of the font and any part of the modification by yourself.
P+theme(axis.text.x = element_text(size = 15),
axis.text.y = element_text(size = 15),
axis.title.x = element_text(size = 18),
axis.title.y = element_text(size = 18),
text = element_text(family = windowsFont("serif")))
The new Rome is to change the windowsFont here
p+theme(axis.text.x = element_text(size = 15),
axis.text.y = element_text(size = 15),
axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
text = element_text(family = windowsFont("TT Times New Roman")))