Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cyk0315 committed Jan 25, 2024
1 parent 757f69d commit dd023eb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
20 changes: 15 additions & 5 deletions R/jskm.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand All @@ -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)

}
}
}


Expand All @@ -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)
Expand Down Expand Up @@ -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')
}

Expand Down
19 changes: 14 additions & 5 deletions R/svyjskm.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,31 @@ 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
if (showpercent == TRUE) {
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)
Expand Down Expand Up @@ -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')
}

Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<!-- -->
Expand Down Expand Up @@ -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)<!-- -->
Binary file modified man/figures/README-unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd023eb

Please sign in to comment.