Skip to content

Commit 578ee3f

Browse files
committed
Add theme_survHE
1 parent bfb7b1c commit 578ee3f

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: survHE
22
Title: Survival Analysis in Health Economic Evaluation
3-
Version: 2.0.4
3+
Version: 2.0.5
44
Date: 2025-05-15
55
Authors@R: c(
66
person(given = "Gianluca",family = "Baio",role = c("aut", "cre"),email = "g.baio@ucl.ac.uk"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(markov_trace)
1818
export(make_data_multi_state)
1919
export(make_newdata)
2020
export(make.transition.probs)
21+
export(theme_survHE)
2122
import(flexsurv)
2223
import(methods)
2324
import(dplyr)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.5
2+
3+
* Adds a `ggplot` theme `theme_survHE` to be used with combined plots (eg for a `survextrap` element)
4+
15
# 2.0.4
26

37
* Fixes a slight mistake in the table for the Gen F. Now works properly on the beta coefficients

R/utils_plot_survHE.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,42 @@ make_newdata=function(data,vars,conts=NULL) {
302302
}
303303

304304

305+
#' A Custom ggplot2 Theme for Survival Plots
306+
#'
307+
#' This theme is designed for use with survival analysis plots, particularly
308+
#' those created using the `survHE` package. It builds on `theme_bw()` and
309+
#' customizes axis text, titles, plot background, and legend styling.
310+
#'
311+
#' Note: To position the legend inside the plot, use an additional call to
312+
#' `theme(legend.position = c(x, y), legend.justification = c("left", "top"))`.
313+
#'
314+
#' @return A ggplot2 theme object that can be added to a ggplot.
315+
#' @examples
316+
#' library(ggplot2)
317+
#' library(survHE)
318+
#' ggplot(mtcars, aes(wt, mpg)) +
319+
#' geom_point() +
320+
#' theme_survHE() +
321+
#' theme(legend.position = c(0.6, 0.8), legend.justification = c("left", "top"))
322+
#' @export
323+
theme_survHE <- function() {
324+
theme_bw() +
325+
theme(
326+
axis.text.x = element_text(color = "black", size = 12),
327+
axis.text.y = element_text(color = "black", size = 12),
328+
axis.title.x = element_text(color = "black", size = 14),
329+
axis.title.y = element_text(color = "black", size = 14),
330+
axis.line = element_line(colour = "black"),
331+
panel.background = element_blank(),
332+
panel.border = element_blank(),
333+
plot.title = element_text(size = 18, face = "bold"),
334+
legend.position = "none", # Default to off; override as needed
335+
legend.background = element_blank(),
336+
legend.title = element_text(size = 15, face = "bold"),
337+
legend.text = element_text(colour = "black", size = 14, face = "plain")
338+
)
339+
}
340+
305341

306342
#' Make the dataset to be used by \code{ggplot2} to plot the survival curves
307343
#'

man/theme_survHE.Rd

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)