I use the plot_model function of sjplot to plot regression models. The regression contains an outcome (C, with 3 levels) and 1 continuous predictor A and D and a categorical B.
I would like to adjust the name of the facets (eg. change name instead of C to have a "This is C=0.11"). is there a way to adjust this?
Sample code:
library(sjPlot) library(sjmisc) library(sjlabelled)
theme_set(theme_sjplot())
df <- read_csv("stacks.csv")
colnames(df)=c("A", "B","C", "D")
df$B<-factor(df$B ,c(1,2), labels=c("FT", "PT"))
model1 <- lm(D ~ A +
relevel(B, ref = "FT")+
A*relevel(B, ref = "FT")+
A*C,
data = df)
set_theme( #To remove the background color and the grids
theme.font = 'serif', #To change the font type
axis.title.size = 1.5, #To change axis title size
axis.textsize.x = 1.2, #To change x axis text size
axis.textsize.y = 1.2,
title.size=1.5,
axis.textcolor = "black", #To change y axis text size
geom.outline.color = "black",
axis.line.size = 3,
base = theme_bw())
p1<-plot_model(model1, type = "pred", show.p = TRUE,terms = c("A", "B", "C"), axis.title = c("", "" ), title = "")
(p1_f<-p1+geom_line(size = 1)+ xlim(0, 10.00)+ theme(plot.title = element_text(hjust = 0.5))+theme(legend.position = "top"))
Sample data:
structure(list(A = c(2.5, 9.5, 9, 13, 9.25, 10.25, 5, 0, 10.25,
8.25, 7.5, 7.25, 4.5, 8.5, 7.5, 9.5, 8, 11.5, 0, 5.5, 9, 6.5,
10.5, 9, 9, 5.5, 10.25, 0, 1, 5.25, 9, 3.5, 9.25, 8.25, 9, 0,
0, 0, 7, 9.75, 9.25, 0, 10.5, 9.75, 2, 13, 9, 0, 8.5, 8, 6.75,
0, 7.75, 9, 8.5, 5.25, 9.5, 7.75, 13.25, 6, 1.5, 8.5, 4.25, 4.75,
0, 4, 11, 7.25, 9.25, 5, 9.25, 5, 5, 8.5, 15, 10.25, 0, 0, 9.75,
7), B = structure(c(1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L,
2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 1L, 1L), .Label = c("FT", "PT"), class = "factor"),
C = c(0.413194444, 0.395224172, 0, 0.137362637, 666, 0.0625,
0.382352941, 0.074074074, 0.277472527, 0.413194444, 0.395224172,
0, 0.137362637, 666, 0.0625, 0.382352941, 0.074074074, 0.277472527,
0.411111111, 0, 0.071428571, 0.090659341, 0.272058824, 0.029220779,
666, 0.142857143, 0.446428571, 0.416666667, 0.287878788,
0.3, 0.208333333, 0.076923077, 666, 0.273897059, 666, 0.252747253,
666, 0.577922078, 666, 666, 0.2875, 0.555860806, 0.085416667,
0.158333333, 0.111111111, 0.206043956, 0.111111111, 0.126482213,
0, 0.037878788, 0.197802198, 0.1375, 666, 666, 666, 666,
0.262820513, 0.663398693, 666, 666, 0.276515152, 0.5, 0.636363636,
0.030701754, 0.476190476, 666, 0.435897436, 666, 0.316544118,
666, 0.152380952, 0.1, 0.454545455, 666, 0.188888889, 0.273809524,
666, 0.538461538, 0.022671569, 666), D = c(80, 180, 100,
0, 260, 140, 160, 120, 130, 180, 90, 150, 90, 150, 260, 190,
240, 10, 110, 130, 140, 240, 60, 60, 0, 60, 200, 150, 20,
0, 240, 200, 90, 0, 50, 0, 0, 30, 40, 130, 0, 40, 220, 50,
150, 30, 130, 140, 220, 190, 320, 90, 0, 130, 150, 0, 150,
190, 80, 310, 150, 350, 30, 40, 80, 310, 100, 10, 80, 200,
200, 340, 190, 150, 90, 230, 380, 1070, 100, 160)), row.names = c(NA,
-80L), class = c("tbl_df", "tbl", "data.frame"))
Sample output: