EDITED: I have a large data base trying to reapeatedly assess energy expenditue over time with the aim to compare multiple different variables (0/1, e.g. presence of severe head trauma vs. no such). The graph analysis should be repeated for all available variables in the database. All tables should be exported to a PDF File.
Currently I'm using the following code:
library(tidyverse)
library(ggpmisc)
my_data %>%
pdf(file="Plots.pdf" )
print(colnames(my_data) %>%
map(function(x) my_data%>%
ggplot(aes(x = Day,
y = REE,
color=as_factor(x)))+
scale_x_continuous(breaks = c(0,2,4,6,8,10,12,14,16,18,20,22,24,26,28))+
scale_y_continuous(limits= c(0000,4000))+
geom_point()+
geom_smooth(method=lm,
se=TRUE,
size=2/10,
aes(group=as_factor(x)))+
stat_poly_eq(aes(label = paste(after_stat(eq.label),
after_stat(rr.label),
after_stat(p.value.label),
sep = "*\", \"*")),
label.y="bottom", label.x="right")+
labs(x="Time [d]",
y="Resting Energy Expenditure [kcal]")+
scale_colour_grey(start=0.7,
end=0.3)+
theme_bw()
))
dev.off()
It generates the PDF File with all graphs. However, it does not group/color according to the as_factor(x) and all data points are categorised into the same group.
Does anyone have a possible explanation on how to resolve this problem that the categorising according to the factor variable doesn't work?


