get_title.Rd
Get variable and value labels from ggeffects
-objects. Functions
like ggpredict()
or ggeffect()
save
information on variable names and value labels as additional attributes
in the returned data frame. This is especially helpful for labelled
data (see sjlabelled), since these labels can be used to
set axis labels and titles.
get_title(x, case = NULL) get_x_title(x, case = NULL) get_y_title(x, case = NULL) get_legend_title(x, case = NULL) get_legend_labels(x, case = NULL) get_x_labels(x, case = NULL) get_complete_df(x, case = NULL)
x | An object of class |
---|---|
case | Desired target case. Labels will automatically converted into the
specified character case. See |
The titles or labels as character string, or NULL
, if variables
had no labels; get_complete_df()
returns the input list x
as single data frame, where the grouping variable indicates the
marginal effects for each term.
library(sjmisc) data(efc) efc$c172code <- to_factor(efc$c172code) fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc) mydf <- ggpredict(fit, terms = c("c12hour", "c161sex", "c172code")) library(ggplot2) ggplot(mydf, aes(x = x, y = predicted, colour = group)) + stat_smooth(method = "lm") + facet_wrap(~facet, ncol = 2) + labs( x = get_x_title(mydf), y = get_y_title(mydf), colour = get_legend_title(mydf) )#> $c12hour #> #> # Predicted values of Total score BARTHEL INDEX #> # x = average number of hours of care per week #> #> x | Predicted | SE | 95% CI #> --------------------------------------- #> 0 | 75.44 | 1.12 | [73.25, 77.63] #> 20 | 70.38 | 0.93 | [68.56, 72.19] #> 45 | 64.05 | 0.84 | [62.39, 65.70] #> 65 | 58.98 | 0.93 | [57.16, 60.81] #> 85 | 53.92 | 1.12 | [51.71, 56.12] #> 105 | 48.85 | 1.38 | [46.15, 51.55] #> 125 | 43.79 | 1.66 | [40.52, 47.06] #> 170 | 32.39 | 2.37 | [27.74, 37.05] #> #> #> $neg_c_7 #> #> # Predicted values of Total score BARTHEL INDEX #> # x = Negative impact with 7 items #> #> x | Predicted | SE | 95% CI #> -------------------------------------- #> 6 | 78.07 | 1.56 | [75.01, 81.14] #> 8 | 73.51 | 1.21 | [71.14, 75.88] #> 12 | 64.39 | 0.84 | [62.73, 66.04] #> 14 | 59.82 | 0.97 | [57.91, 61.73] #> 16 | 55.26 | 1.26 | [52.79, 57.73] #> 20 | 46.13 | 2.02 | [42.16, 50.10] #> 22 | 41.57 | 2.44 | [36.78, 46.36] #> 28 | 27.88 | 3.74 | [20.55, 35.22] #> #> #> $c161sex #> #> # Predicted values of Total score BARTHEL INDEX #> # x = carer's gender #> #> x | Predicted | SE | 95% CI #> ------------------------------------- #> 1 | 64.09 | 1.73 | [60.69, 67.49] #> 2 | 64.96 | 0.97 | [63.07, 66.86] #> #> #> $c172code #> #> # Predicted values of Total score BARTHEL INDEX #> # x = carer's level of education #> #> x | Predicted | SE | 95% CI #> ------------------------------------- #> 1 | 62.79 | 1.83 | [59.21, 66.38] #> 2 | 65.68 | 1.08 | [63.55, 67.81] #> 3 | 64.01 | 1.97 | [60.14, 67.88] #> #> #> attr(,"class") #> [1] "ggalleffects" "list"get_complete_df(eff)#> #> # Predicted values of Total score BARTHEL INDEX #> # x = average number of hours of care per week #> #> # c12hour #> #> x | Predicted | SE | 95% CI #> --------------------------------------- #> 0 | 75.44 | 1.12 | [73.25, 77.63] #> 35 | 66.58 | 0.85 | [64.91, 68.25] #> 70 | 57.71 | 0.97 | [55.81, 59.62] #> 100 | 50.12 | 1.31 | [47.55, 52.69] #> 170 | 32.39 | 2.37 | [27.74, 37.05] #> #> # c161sex #> #> x | Predicted | SE | 95% CI #> ------------------------------------- #> 1 | 64.09 | 1.73 | [60.69, 67.49] #> 2 | 64.96 | 0.97 | [63.07, 66.86] #> #> # c172code #> #> x | Predicted | SE | 95% CI #> ------------------------------------- #> 1 | 62.79 | 1.83 | [59.21, 66.38] #> 2 | 65.68 | 1.08 | [63.55, 67.81] #> 3 | 64.01 | 1.97 | [60.14, 67.88] #> #> # neg_c_7 #> #> x | Predicted | SE | 95% CI #> -------------------------------------- #> 6 | 78.07 | 1.56 | [75.01, 81.14] #> 10 | 68.95 | 0.94 | [67.11, 70.79] #> 14 | 59.82 | 0.97 | [57.91, 61.73] #> 20 | 46.13 | 2.02 | [42.16, 50.10] #> 28 | 27.88 | 3.74 | [20.55, 35.22] #># get marginal effects for education only, and get x-axis-labels mydat <- eff[["c172code"]] ggplot(mydat, aes(x = x, y = predicted, group = group)) + stat_summary(fun.y = sum, geom = "line") + scale_x_discrete(labels = get_x_labels(mydat))