Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 9, 2022 15:59
Show Gist options
  • Save MJacobs1985/b875193c24e78eb4e23b2ad7ef149924 to your computer and use it in GitHub Desktop.
Save MJacobs1985/b875193c24e78eb4e23b2ad7ef149924 to your computer and use it in GitHub Desktop.
try<-qol_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="QOL_13"|variable=="QOL_14")%>%
dplyr::group_by(Patientnr,time)%>%arrange(Patientnr, time);head(try);dim(try)
g1<-ggplot(try, aes(x=as.factor(time),y=as.factor(variable),fill=as.factor(value)))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = TRUE, option="magma", direction = -1 )+
facet_wrap(~Patientnr)+
theme_grey(base_size=10)+marc_discrete
EF_QOL<-try%>%dplyr::summarise(ef = sum(value), efsum = 8-ef) %>%
dplyr::mutate(ef = case_when(
efsum == 0 ~ 0,
efsum == 1 ~ 2*100/12,
efsum == 2 ~ 5*100/12,
efsum == 3 ~ 50,
efsum == 4 ~ 8*100/12,
efsum == 5 ~ 10*100/12,
efsum == 6 ~ 100,
TRUE ~ -1));head(EF_QOL);dim(EF_QOL)
EF_QOL$ef<-ifelse(EF_QOL$ef==-1, NA, EF_QOL$ef);head(EF_QOL);histogram(EF_QOL$ef)
g2<-ggplot(EF_QOL,aes(x=as.factor(time), y=ef, group=as.factor(Patientnr)))+ geom_line() + geom_point() + facet_wrap(~Patientnr) + theme_bw()
g3<-ggplot(EF_QOL,aes(x=as.factor(time),y=ef))+geom_boxplot()+theme_bw()
g4<-ggplot(EF_QOL,aes(x=as.factor(time),y=as.factor(Patientnr),fill=ef))+geom_tile(colour="white",size=0.25, na.rm=TRUE)+
labs(x="",y="")+scale_y_discrete(expand=c(0,0))+
scale_fill_viridis(discrete = FALSE, option="mako", direction = -1 )+
theme_grey(base_size=10)+marc_discrete
grid.arrange(g1,g4,g2,g3,ncol=4, top="Emotional Functioning")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment