Vertical Venn
source("code/utils.R")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ stringr 1.4.1
## ✔ tidyr 1.2.1 ✔ forcats 0.5.2
## ✔ readr 2.1.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## Loading required package: ggpubr
##
##
## Attaching package: 'survminer'
##
##
## The following object is masked from 'package:survival':
##
## myeloma
##
##
##
## Attaching package: 'reshape'
##
##
## The following objects are masked from 'package:tidyr':
##
## expand, smiths
##
##
## The following object is masked from 'package:dplyr':
##
## rename
##
##
##
## Attaching package: 'gridExtra'
##
##
## The following object is masked from 'package:dplyr':
##
## combine
##
##
##
## Attaching package: 'survMisc'
##
##
## The following object is masked from 'package:ggplot2':
##
## autoplot
##
##
##
## Attaching package: 'rsq'
##
##
## The following object is masked from 'package:survMisc':
##
## rsq
##
##
## Type 'citation("pROC")' for a citation.
##
##
## Attaching package: 'pROC'
##
##
## The following object is masked from 'package:survMisc':
##
## ci
##
##
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
##
##
##
## Attaching package: 'data.table'
##
##
## The following object is masked from 'package:reshape':
##
## melt
##
##
## The following object is masked from 'package:purrr':
##
## transpose
##
##
## The following objects are masked from 'package:dplyr':
##
## between, first, last
##
##
##
## Attaching package: 'plotly'
##
##
## The following object is masked from 'package:reshape':
##
## rename
##
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
##
## The following object is masked from 'package:stats':
##
## filter
##
##
## The following object is masked from 'package:graphics':
##
## layout
df=data.frame(readRDS("output/amit_df.rds"))
df$chd=df$phenos.has_CAD
df$AGE1=df$phenos.enrollment
# m=rbind(df[,c("AGE1","prs.r","ascvd_10y_accaha","chd")],dff[,c("AGE1","prs.r","ascvd_10y_accaha","chd")])
#
# df=m
# df=df[df$AGE1>=40&df$AGE1<=70,]
library(scales)
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
hex <- hue_pal()(6)
i=df %>% mutate(ints=cut(AGE1,breaks=c(39.99,45,50,55,60,65,70,75)))
i=i[!is.na(i$ints),]
fulla=i%>%group_by(ints)%>%summarise("Low"=mean(ascvd_10y_accaha_all<7.5),"Intermediate"=mean(ascvd_10y_accaha_all>7.5&ascvd_10y_accaha_all<20),"High"=mean(ascvd_10y_accaha_all>20),"n"=length(ints))
#
errors=sqrt(fulla[,c(2:4)]*(1-fulla[,c(2:4)])/fulla$n)
errors=cbind("ints"=fulla$ints,errors)
colnames(errors)=colnames(fulla)[1:4]
hex <- c("green","orange","red")
#
# mat=as.matrix(fulla[,c(2:3)])*100
#
# barplot(t(mat),beside = T,names=fulla$ints,legend=F,col=c(hex[c(1,3)]),main="FHS+UKB Incident Cases Correctly Predicted",ylab="Proportion of Incident Cases Correctly Predicted",las=2)
# legend("topleft",legend=c("PRS only","PCE only"),fill =c(hex[c(1,3)]))
#
r=melt(data.frame(fulla[,c(1,2,4,3)]),id.vars = "ints")
## Warning in melt(data.frame(fulla[, c(1, 2, 4, 3)]), id.vars = "ints"): The melt
## generic in data.table has been passed a data.frame and will attempt to redirect
## to the relevant reshape2 method; please note that reshape2 is deprecated, and
## this redirection is now deprecated as well. To continue using melt methods from
## reshape2 while both libraries are attached, e.g. melt.list, you can prepend the
## namespace like reshape2::melt(data.frame(fulla[, c(1, 2, 4, 3)])). In the next
## version, this warning will become an error.
s=melt(data.frame(errors),id.vars = "ints")
## Warning in melt(data.frame(errors), id.vars = "ints"): The melt generic in
## data.table has been passed a data.frame and will attempt to redirect to the
## relevant reshape2 method; please note that reshape2 is deprecated, and this
## redirection is now deprecated as well. To continue using melt methods from
## reshape2 while both libraries are attached, e.g. melt.list, you can prepend the
## namespace like reshape2::melt(data.frame(errors)). In the next version, this
## warning will become an error.
r$lower=r$value-s$value
r$upper=r$value+s$value
names(r)[2]="ASCVD 10 year-Risk"
r$`ASCVD 10 year-Risk`=factor(r$`ASCVD 10 year-Risk`,levels=c("Low","Intermediate","High"),labels=c("<7.5","7.5-20",">20"))
p <- ggplot(data=r, aes(x=ints, y = value,fill = `ASCVD 10 year-Risk`)) + geom_bar(stat="identity") +labs(y = "Proportion of People",x="Age at Risk Estimation")+scale_fill_manual(values=c("#00b159","#f37735","#d11141"))+theme_classic(base_size = 25)+tems#+geom_errorbar(aes(ymin = value-error, ymax = value+error), width = 0.3, position = "identity")
p

ggplot2::ggsave(p,filename = "Figs/Supplemental/proportion_plots_ascvd.tiff",dpi = 300,height = 5,width = 8)
write.table(r,"output/proportions_table_ascvd.csv",sep=",",row.names = F,quote=F)