Created
November 9, 2022 16:11
-
-
Save MJacobs1985/072d664fb790bb845b8126e16901382c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Severity_BPI2<-Severity_BPI | |
Severity_BPI2<-ddply(Severity_BPI2,.(Patientnr),.drop=FALSE,transform,baselinechange=Severity-Severity[1]) | |
Severity_BPI3<-Severity_BPI | |
Severity_BPI3<-ddply(Severity_BPI3,.(Patientnr),.drop=FALSE,transform,change=Severity-lag(Severity)) | |
Severity_BPI$Severity_baselinechange<-Severity_BPI2$baselinechange | |
Severity_BPI$Severity_change<-Severity_BPI3$change | |
Severity_BPI$Severity_baselinechange[Severity_BPI$time==0]<-NA | |
Severity_BPI$Severity_change[Severity_BPI$time==0]<-NA | |
Severity_BPI | |
# Check visually if worked | |
g2<-ggplot(Severity_BPI,aes(x=as.factor(time), y=Severity, group=as.factor(Patientnr))) + geom_line() + geom_point() + facet_wrap(~Patientnr) + theme_bw() | |
g1<-ggplot(Severity_BPI,aes(x=as.factor(time), y=as.factor(Patientnr),fill=Severity)) + 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="magma", direction = -1)+ theme_grey(base_size=10)+marc_discrete | |
g3<-ggplot(Severity_BPI) + geom_bar(aes(as.factor(time), Severity_baselinechange), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Patientnr)+ theme_bw() | |
g4<-ggplot(Severity_BPI) + geom_bar(aes(as.factor(time), Severity_change), position = "dodge", stat = "summary", fun.y = "mean") + facet_wrap(~Patientnr)+ theme_bw() | |
grid.arrange(g1,g2,g3,g4,ncol=4, top="BPI Severity Changes ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment