Skip to content

Commit

Permalink
fix: Duplicate pvalue in theme nejm
Browse files Browse the repository at this point in the history
  • Loading branch information
cyk0315 committed Jan 24, 2024
1 parent 6d46874 commit 7e5688d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
11 changes: 6 additions & 5 deletions R/jskm.R
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,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 @@ -475,7 +475,7 @@ jskm <- function(sfit,

pvaltxt <- ifelse(pvalue < 0.001, "p < 0.001", paste("p =", round(pvalue, 3)))
if (pval.testname) pvaltxt <- paste0(pvaltxt, " (Log-rank)")

# MOVE P-VALUE LEGEND HERE BELOW [set x and y]
if (is.null(pval.coord)) {
p <- p + annotate("text", x = (as.integer(max(sfit$time) / 5)), y = 0.1 + ylims[1], label = pvaltxt, size = pval.size)
Expand Down Expand Up @@ -511,7 +511,7 @@ jskm <- function(sfit,
pvaltxt <- ifelse(pvalue < 0.001, "p < 0.001", paste("p =", round(pvalue, 3)))

if (pval.testname) pvaltxt <- paste0(pvaltxt, " (Log-rank)")

if (is.null(pval.coord)) {
p <- p + annotate("text", x = c(as.integer(max(sfit$time) / 10), as.integer(max(sfit$time) / 10) + cut.landmark), y = 0.1 + ylims[1], label = pvaltxt, size = pval.size)
} else {
Expand Down Expand Up @@ -569,13 +569,14 @@ jskm <- function(sfit,
#######################

if(!is.null(theme)&&theme == 'nejm') {
p2<-p+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())
p<- p + patchwork::inset_element(p2, 1-nejm.infigure.ratiow,1-nejm.infigure.ratioh, 1, 1,align_to = 'panel')
}

if (table == TRUE) {
ggpubr::ggarrange(p, blank.pic, data.table,
nrow = 3, align = "v",
nrow = 3,
#align = "v",
heights = c(2, .1, .25)
)
} else {
Expand Down
32 changes: 17 additions & 15 deletions R/svyjskm.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,19 @@ svyjskm <- function(sfit,
## 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 {
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")
}
}
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 @@ -395,18 +407,7 @@ svyjskm <- function(sfit,
}
}

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 {
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")
}
}




Expand Down Expand Up @@ -512,13 +513,14 @@ svyjskm <- function(sfit,
# Plotting the graphs #
#######################
if(!is.null(theme)&&theme == 'nejm') {
p2<-p+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())
p<- p + patchwork::inset_element(p2, 1-nejm.infigure.ratiow,1-nejm.infigure.ratioh, 1, 1,align_to = 'panel')
}

if (table == TRUE) {
ggpubr::ggarrange(p, blank.pic, data.table,
nrow = 3, align = "v",
nrow = 3,
#align = "v",
heights = c(2, .1, .25)
)
} else {
Expand Down

0 comments on commit 7e5688d

Please sign in to comment.