-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_lca.txt
62 lines (51 loc) · 1.52 KB
/
plot_lca.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
library(MplusAutomation)
library(tidyverse)
library(reshape2)
library(cowplot)
library(glue)
plot_lca <-
function(model_name) {
pp_plots <- data.frame(model_name$parameters$probability.scale) %>%
mutate(LatentClass = sub("^","Class ", LatentClass)) %>%
filter(category == 2) %>%
dplyr::select(est, LatentClass, param) %>%
pivot_wider(names_from = LatentClass, values_from = est) %>%
relocate(param, .after = last_col())
c_size <- as.data.frame(model_name$class_counts$modelEstimated$proportion) %>%
rename("cs" = 1) %>%
mutate(cs = round(cs * 100, 2))
colnames(pp_plots) <- paste0(colnames(pp_plots[,1:ncol(pp_plots)-1]), glue(" ({c_size[1:ncol(pp_plots)-1,]}%)"))
plot_data <- pp_plots %>%
rename("param" = ncol(pp_plots)) %>%
reshape2::melt(id.vars = "param") %>%
mutate(param = fct_inorder(param))
name <- model_name$input$title
p <- plot_data %>%
ggplot(
aes(
x = param,
y = value,
shape = variable,
colour = variable,
lty = variable,
group = variable
)
) +
geom_point(size = 4) + geom_line() +
ylim(0,1) +
scale_x_discrete("") +
labs(title = glue("{name} Probability Plot"), y = "Probability") +
theme_cowplot() +
theme(
text = element_text(family = "serif", size = 12),
legend.text = element_text(family = "serif", size = 12),
legend.key.width = unit(0, "line"),
legend.title = element_blank(),
legend.position = "top",
axis.text.x = element_text(
vjust = 1
)
)
p
return(p)
}