Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created November 9, 2022 16:00
Show Gist options
  • Save MJacobs1985/5af7966d55cb6edcb813f239f2b4adc8 to your computer and use it in GitHub Desktop.
Save MJacobs1985/5af7966d55cb6edcb813f239f2b4adc8 to your computer and use it in GitHub Desktop.
try<-qol_combined%>%dplyr::select(Patientnr,time,variable,value)%>%
dplyr::filter(variable=="QOL_7_"|variable=="QOL_11")%>%
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
FA_QOL<-try%>%
dplyr::summarise(variable=variable, value=value, fa = sum(value), fasum = fa-2) %>%
dplyr::mutate(fa = case_when(
fasum == 0 ~ 0,
fasum == 1 ~ 2*100/9,
fasum == 2 ~ 3*100/9,
fasum == 4 ~ 6*100/9,
fasum == 5 ~ 8*100/9,
fasum == 6 ~ 100))
dim(FA_QOL)
FA_QOL[FA_QOL$Patientnr=="2",] # Example of a patient that has fasum = 3 and hence no fa score because of it
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_7_" & value==1 & fasum==3), 5*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_7_" & value==2 & fasum==3), 5*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_7_" & value==3 & fasum==3), 4*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_7_" & value==4 & fasum==3), 4*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_11" & value==4 & fasum==3), 5*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_11" & value==3 & fasum==3), 5*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_11" & value==2 & fasum==3), 4*100/9, fa))
FA_QOL<-FA_QOL%>%dplyr::mutate(fa = if_else((variable=="QOL_11" & value==1 & fasum==3), 4*100/9, fa))
FA_QOL[FA_QOL$Patientnr=="2",] # Example of a patient that has fasum = 3
dim(FA_QOL);head(FA_QOL);str(FA_QOL)
FA_QOL$variable<-NULL
FA_QOL$value<-NULL
dim(FA_QOL);head(FA_QOL);str(FA_QOL)
FA_QOL<-FA_QOL[!duplicated(FA_QOL),];head(FA_QOL);dim(FA_QOL)
histogram(FA_QOL$fa)
g3<-ggplot(FA_QOL,aes(x=as.factor(time), y=fa, group=as.factor(Patientnr)))+ geom_line() + geom_point() + facet_wrap(~Patientnr) + theme_bw()
g4<-ggplot(FA_QOL, aes(x=as.factor(time),y=fa))+geom_boxplot()+theme_bw()
g2<-ggplot(FA_QOL,aes(x=as.factor(time),y=as.factor(Patientnr),fill=fa))+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,g2,g3,g4,ncol=4, top="Fatigue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment