diff --git a/R/jskm.R b/R/jskm.R index ae24752..49f2f5d 100644 --- a/R/jskm.R +++ b/R/jskm.R @@ -404,7 +404,7 @@ jskm <- function(sfit, if (!is.null(cut.landmark)) { p <- p + geom_vline(xintercept = cut.landmark, lty = 2) } - + p1<-p if (showpercent == T) { if (is.null(cut.landmark)) { y.percent <- summary(sfit, times = xlims[2], extend = T)$surv @@ -413,7 +413,11 @@ jskm <- function(sfit, } if (cumhaz == T & is.null(sfit$states)) y.percent <- 1 - y.percent p <- p + annotate(geom = "text", x = xlims[2], y = y.percent, label = paste0(round(100 * y.percent, 1), "%"), color = "black") - } else { + if(!is.null(theme)&&theme == 'nejm') { + p1 <- p1 + annotate(geom = "text", x = xlims[2], y = y.percent, label = paste0(round(100 * y.percent, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + + } + } else { y.percent1 <- summary(sfit, times = cut.landmark, extend = T)$surv y.percent2 <- summary(sfit2, times = xlims[2], extend = T)$surv if (!is.null(sfit$states)) { @@ -426,7 +430,12 @@ jskm <- function(sfit, } p <- p + annotate(geom = "text", x = cut.landmark, y = y.percent1, label = paste0(round(100 * y.percent1, 1), "%"), color = "black") + annotate(geom = "text", x = xlims[2], y = y.percent2, label = paste0(round(100 * y.percent2, 1), "%"), color = "black") - } + if(!is.null(theme)&&theme == 'nejm') { + p1 <- p1 + annotate(geom = "text", x = cut.landmark, y = y.percent1, label = paste0(round(100 * y.percent1, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + + annotate(geom = "text", x = xlims[2], y = y.percent2, label = paste0(round(100 * y.percent2, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + + } + } } @@ -447,7 +456,7 @@ jskm <- function(sfit, if (length(levels(summary(sfit)$strata)) == 0) pval <- F # if(!is.null(cut.landmark)) pval <- F - p1<-p + if (pval == TRUE) { if (is.null(data)) { data <- tryCatch(eval(sfit$call$data), error = function(e) e) @@ -569,7 +578,8 @@ jskm <- function(sfit, ####################### if(!is.null(theme)&&theme == 'nejm') { - p2<-p1+coord_cartesian(ylim=nejm.infigure.ylim)+theme(legend.position='none',axis.title.x = element_blank(),axis.title.y=element_blank()) + p2<-p1+coord_cartesian(ylim=nejm.infigure.ylim)+theme(legend.position='none',axis.title.x = element_blank(),axis.title.y=element_blank(), + axis.text= element_text(size=10*nejm.infigure.ratiow)) p<- p + patchwork::inset_element(p2, 1-nejm.infigure.ratiow,1-nejm.infigure.ratioh, 1, 1,align_to = 'panel') } diff --git a/R/svyjskm.R b/R/svyjskm.R index e6efc08..88f403c 100644 --- a/R/svyjskm.R +++ b/R/svyjskm.R @@ -334,7 +334,8 @@ svyjskm <- function(sfit, if (!is.null(cut.landmark)) { p <- p + geom_vline(xintercept = cut.landmark, lty = 2) } - + + p1<-p ## p-value if (inherits(sfit, "svykm")) pval <- FALSE # if(is.null(design)) pval <- FALSE @@ -342,15 +343,22 @@ svyjskm <- function(sfit, if (is.null(cut.landmark)) { y.percent <- df[df$time %in% tapply(df$time, df$strata, max), "surv"] p <- p + annotate(geom = "text", x = xlims[2], y = y.percent, label = paste0(round(100 * y.percent, 1), "%"), color = "black") - } else { + if(!is.null(theme)&&theme == 'nejm') { + p1 <- p1 + annotate(geom = "text", x = xlims[2], y = y.percent, label = paste0(round(100 * y.percent, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + } + } else { df.cut <- df[df$time < cut.landmark, ] y.percent1 <- df.cut[df.cut$time %in% tapply(df.cut$time, df.cut$strata, max), "surv"] y.percent2 <- df[df$time %in% tapply(df$time, df$strata, max), "surv"] p <- p + annotate(geom = "text", x = cut.landmark, y = y.percent1, label = paste0(round(100 * y.percent1, 1), "%"), color = "black") + annotate(geom = "text", x = xlims[2], y = y.percent2, label = paste0(round(100 * y.percent2, 1), "%"), color = "black") - } + if(!is.null(theme)&&theme == 'nejm') { + p1 <- p1 + annotate(geom = "text", x = cut.landmark, y = y.percent1, label = paste0(round(100 * y.percent1, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + + annotate(geom = "text", x = xlims[2], y = y.percent2, label = paste0(round(100 * y.percent2, 1), "%"), color = "black",size=nejm.infigure.ratiow*5) + + } + } } - p1<-p if (pval) { if (is.null(design)) { design <- tryCatch(get(as.character(attr(sfit, "call")$design)), error = function(e) e) @@ -520,7 +528,8 @@ svyjskm <- function(sfit, # Plotting the graphs # ####################### if(!is.null(theme)&&theme == 'nejm') { - p2<-p1+coord_cartesian(ylim=nejm.infigure.ylim)+theme(legend.position='none',axis.title.x = element_blank(),axis.title.y=element_blank()) + p2<-p1+coord_cartesian(ylim=nejm.infigure.ylim)+theme(legend.position='none',axis.title.x = element_blank(),axis.title.y=element_blank() + ,axis.text= element_text(size=10*nejm.infigure.ratiow)) p<- p + patchwork::inset_element(p2, 1-nejm.infigure.ratiow,1-nejm.infigure.ratioh, 1, 1,align_to = 'panel') } diff --git a/README.Rmd b/README.Rmd index b1a433a..4927a8f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -88,7 +88,7 @@ jskm(fit, theme='jama', cumhaz = T, table=T, mark = F, ylab = "Cumulative incide #### NEJM ```{r} -jskm(fit, theme='nejm', nejm.infigure.ratiow = 0.6, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0,0.7), cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7)) +jskm(fit, theme='nejm', nejm.infigure.ratiow = 0.7, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0,0.7), cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7)) ``` ### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package @@ -129,5 +129,5 @@ svyjskm(s2, theme='jama', pval = T, table = T, design = dpbc) #### NEJM ```{r} -svyjskm(s2, theme='nejm', nejm.infigure.ratiow = 0.4, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2,1), pval = T, table = T, design = dpbc) +svyjskm(s2, theme='nejm', nejm.infigure.ratiow = 0.45, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2,1), pval = T, table = T, design = dpbc) ``` diff --git a/README.md b/README.md index 41f6ddb..03e01a3 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ jskm(fit, theme='jama', cumhaz = T, table=T, mark = F, ylab = "Cumulative incide #### NEJM ``` r -jskm(fit, theme='nejm', nejm.infigure.ratiow = 0.6, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0,0.7), cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7)) +jskm(fit, theme='nejm', nejm.infigure.ratiow = 0.7, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0,0.7), cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7)) ``` ![](man/figures/README-unnamed-chunk-6-1.png) @@ -183,7 +183,7 @@ svyjskm(s2, theme='jama', pval = T, table = T, design = dpbc) #### NEJM ``` r -svyjskm(s2, theme='nejm', nejm.infigure.ratiow = 0.4, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2,1), pval = T, table = T, design = dpbc) +svyjskm(s2, theme='nejm', nejm.infigure.ratiow = 0.45, nejm.infigure.ratioh = 0.4, nejm.infigure.ylim = c(0.2,1), pval = T, table = T, design = dpbc) ``` ![](man/figures/README-unnamed-chunk-10-1.png) diff --git a/man/figures/README-unnamed-chunk-10-1.png b/man/figures/README-unnamed-chunk-10-1.png index d23532c..34206c2 100644 Binary files a/man/figures/README-unnamed-chunk-10-1.png and b/man/figures/README-unnamed-chunk-10-1.png differ diff --git a/man/figures/README-unnamed-chunk-6-1.png b/man/figures/README-unnamed-chunk-6-1.png index 567719f..b32fb7f 100644 Binary files a/man/figures/README-unnamed-chunk-6-1.png and b/man/figures/README-unnamed-chunk-6-1.png differ