Skip to content

Commit

Permalink
add theme example in readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cyk0315 committed Jan 25, 2024
1 parent 7e5688d commit cad6de3
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 28 deletions.
11 changes: 9 additions & 2 deletions R/svyjskm.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,20 @@ svyjskm <- function(sfit,
legend.key = element_rect(colour = NA),
panel.border = element_blank(),
plot.margin = unit(c(0, 1, .5, ifelse(m < 10, 1.5, 2.5)), "lines"),
panel.grid.major = element_blank(),
axis.line.x = element_line(linewidth = 0.5, linetype = "solid", colour = "black"),
axis.line.y = element_line(linewidth = 0.5, linetype = "solid", colour = "black")
) +
scale_x_continuous(xlabs, breaks = times, limits = xlims) +
scale_y_continuous(ylabs, limits = ylims, labels = scale_labels)


if(!is.null(theme)&&theme=='jama'){
p<-p+theme(
panel.grid.major.x = element_blank()
)
} else{
p <- p + theme(
panel.grid.major = element_blank()
)}


# Removes the legend:
Expand Down
22 changes: 22 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", showpercent = T, cut.landmark = 500)
```

### Theme Jama

```{r}
jskm(fit, theme='jama', cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7))
```

### Theme Nejmoa

```{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))
```

### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package

Expand Down Expand Up @@ -106,3 +117,14 @@ svyjskm(s3, ci = F)
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000, showpercent = T)
```

### Theme jama

```{r}
svyjskm(s2, theme='jama', pval = T, table = T, design = dpbc)
```

### Theme nejmoa

```{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)
```
86 changes: 60 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,45 @@ library(jskm)
### Survival probability

``` r
#Load dataset
# Load dataset
library(survival)
data(colon)
fit <- survfit(Surv(time,status)~rx, data=colon)
fit <- survfit(Surv(time, status) ~ rx, data = colon)

#Plot the data
# Plot the data
jskm(fit)
```

![](man/figures/README-unnamed-chunk-1-1.png)<!-- -->

``` r
jskm(fit, table = T, pval = T, label.nrisk = "No. at risk", size.label.nrisk = 8,
xlabs = "Time(Day)", ylabs = "Survival", ystratalabs = c("Obs", "Lev", "Lev + 5FU"), ystrataname = "rx",
marks = F, timeby = 365, xlims = c(0, 3000), ylims = c(0.25, 1), showpercent = T)
jskm(fit,
table = T, pval = T, label.nrisk = "No. at risk", size.label.nrisk = 8,
xlabs = "Time(Day)", ylabs = "Survival", ystratalabs = c("Obs", "Lev", "Lev + 5FU"), ystrataname = "rx",
marks = F, timeby = 365, xlims = c(0, 3000), ylims = c(0.25, 1), showpercent = T
)
```

![](man/figures/README-unnamed-chunk-1-2.png)<!-- -->

### Cumulative hazard: 1- Survival probability

``` r
jskm(fit, ci = T, cumhaz = T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7))
jskm(fit, ci = T, cumhaz = 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-2-1.png)<!-- -->

### Landmark analysis

``` r
jskm(fit, mark = F, surv.scale = "percent", pval =T, table = T, cut.landmark = 500)
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500)
```

![](man/figures/README-unnamed-chunk-3-1.png)<!-- -->

``` r
jskm(fit, mark = F, surv.scale = "percent", pval =T, table = T, cut.landmark = 500, showpercent = T)
jskm(fit, mark = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 500, showpercent = T)
```

![](man/figures/README-unnamed-chunk-3-2.png)<!-- -->
Expand All @@ -85,7 +87,7 @@ jskm(fit, mark = F, surv.scale = "percent", pval =T, table = T, cut.landmark =
colon$status2 <- colon$status
colon$status2[1:400] <- 2
colon$status2 <- factor(colon$status2)
fit2 <- survfit(Surv(time,status2)~rx, data=colon)
fit2 <- survfit(Surv(time, status2) ~ rx, data = colon)
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
```

Expand All @@ -97,55 +99,87 @@ jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", sho

![](man/figures/README-unnamed-chunk-4-2.png)<!-- -->

### Theme Jama

``` r
jskm(fit, theme='jama', 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-5-1.png)<!-- -->

### Theme Nejmoa

``` 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))
```

![](man/figures/README-unnamed-chunk-6-1.png)<!-- -->

### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package

``` r
library(survey)
data(pbc, package="survival")
pbc$randomized <- with(pbc, !is.na(trt) & trt>0)
biasmodel <- glm(randomized~age*edema,data=pbc)
data(pbc, package = "survival")
pbc$randomized <- with(pbc, !is.na(trt) & trt > 0)
biasmodel <- glm(randomized ~ age * edema, data = pbc)
pbc$randprob <- fitted(biasmodel)

dpbc<-svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))
dpbc <- svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, randomized))

s1 <-svykm(Surv(time,status>0) ~ 1, design = dpbc)
s2 <-svykm(Surv(time,status>0) ~ sex, design = dpbc)
s1 <- svykm(Surv(time, status > 0) ~ 1, design = dpbc)
s2 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc)

svyjskm(s1)
```

![](man/figures/README-unnamed-chunk-5-1.png)<!-- -->
![](man/figures/README-unnamed-chunk-7-1.png)<!-- -->

``` r
svyjskm(s2, pval = T, table = T, design = dpbc)
svyjskm(s2, pval = T, table = T, design = dpbc)
```

![](man/figures/README-unnamed-chunk-5-2.png)<!-- -->
![](man/figures/README-unnamed-chunk-7-2.png)<!-- -->

``` r
svyjskm(s2, cumhaz = T, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7), showpercent = T)
svyjskm(s2, cumhaz = T, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval = T, design = dpbc, pval.coord = c(300, 0.7), showpercent = T)
```

![](man/figures/README-unnamed-chunk-5-3.png)<!-- -->
![](man/figures/README-unnamed-chunk-7-3.png)<!-- -->

If you want to get **confidence interval**, you should apply `se = T`
option to `svykm` object.

``` r
s3 <- svykm(Surv(time,status>0) ~ sex, design=dpbc, se = T)
s3 <- svykm(Surv(time, status > 0) ~ sex, design = dpbc, se = T)
svyjskm(s3)
```

![](man/figures/README-unnamed-chunk-6-1.png)<!-- -->
![](man/figures/README-unnamed-chunk-8-1.png)<!-- -->

``` r
svyjskm(s3, ci = F)
```

![](man/figures/README-unnamed-chunk-6-2.png)<!-- -->
![](man/figures/README-unnamed-chunk-8-2.png)<!-- -->

``` r
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000, showpercent = T)
```

![](man/figures/README-unnamed-chunk-8-3.png)<!-- -->

### Theme jama

``` r
svyjskm(s2, theme='jama', pval = T, table = T, design = dpbc)
```

![](man/figures/README-unnamed-chunk-9-1.png)<!-- -->

### Theme nejmoa

``` r
svyjskm(s3, ci = F, surv.scale = "percent", pval =T, table = T, cut.landmark = 1000, showpercent = T)
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)
```

![](man/figures/README-unnamed-chunk-6-3.png)<!-- -->
![](man/figures/README-unnamed-chunk-10-1.png)<!-- -->
Binary file modified man/figures/README-unnamed-chunk-1-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-1-2.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 added 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-2-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-3-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-3-2.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-4-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-4-2.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-5-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.
Binary file added man/figures/README-unnamed-chunk-7-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 added man/figures/README-unnamed-chunk-7-2.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 added man/figures/README-unnamed-chunk-7-3.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 added man/figures/README-unnamed-chunk-8-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 added man/figures/README-unnamed-chunk-8-2.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 added man/figures/README-unnamed-chunk-8-3.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 added man/figures/README-unnamed-chunk-9-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 added man/figures/README-unnamed-chunk-9-2.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 added man/figures/README-unnamed-chunk-9-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions vignettes/jskm.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1")
jskm(fit2, mark = F, surv.scale = "percent", table = T, status.cmprsk = "1", showpercent = T, cut.landmark = 500)
```

### Theme Jama

```{r}
jskm(fit, theme='jama', cumhaz = T, table=T, mark = F, ylab = "Cumulative incidence (%)", surv.scale = "percent", pval =T, pval.size = 6, pval.coord = c(300, 0.7))
```

### Theme Nejmoa

```{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))
```

### Weighted Kaplan-Meier plot - `svykm.object` in **survey** package

Expand Down Expand Up @@ -99,3 +110,15 @@ svyjskm(s3, ci = F, showpercent = T)
svyjskm(s3, ci = F, surv.scale = "percent", pval = T, table = T, cut.landmark = 1000)
```

### Theme jama

```{r}
svyjskm(s2, theme='jama', pval = T, table = T, design = dpbc)
```

### Theme nejmoa

```{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)
```

0 comments on commit cad6de3

Please sign in to comment.