Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added plotly support and other fixes to plotting functions #65

Merged
merged 50 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
df14502
Merge pull request #2 from giabaio/master
andbe Jul 17, 2018
22cae4c
Merge pull request #3 from giabaio/master
andbe Mar 28, 2019
74cd964
Update README TO say that this is the stable, development version
giabaio Nov 12, 2023
5592308
Update README TO say that this is the stable, development version
giabaio Nov 12, 2023
636ea0b
Test if using the GH repo for plotrix makes it pass the R checks
giabaio Nov 12, 2023
43dddf3
Update class of smoking output object to avoid issues with rjags
giabaio Nov 21, 2023
472160f
Update DESCRIPTION to load plotrix and remove appveyor + travis
giabaio Nov 21, 2023
e3646f3
Update DESCRIPTION to load plotrix and remove appveyor + travis
giabaio Nov 21, 2023
aa6ed8b
Remove .save files
giabaio Nov 21, 2023
5ecedea
Update NEWS with November changes
giabaio Nov 21, 2023
5c3714d
Add citation file
giabaio Nov 22, 2023
19f644b
Add citation file
giabaio Nov 22, 2023
c41ddba
Add citation file
giabaio Nov 22, 2023
93f926a
Update DESCRIPTION
giabaio Nov 27, 2023
81e4f61
Update README to acknowledge that the latest version is also on CRAN
giabaio Dec 2, 2023
a68115b
Update README to acknowledge that the latest version is also on CRAN
giabaio Dec 2, 2023
399d639
Merge branch 'giabaio:main' into master
andbe Dec 4, 2023
1aedb7e
ceplane.plot ggplot and plotly fixes
andbe Dec 5, 2023
bd11d6c
minor ceplane.plotly fixes
andbe Dec 5, 2023
baa58fb
Added ceef plotly version
andbe Dec 5, 2023
e039045
fixed legends in plotly
andbe Dec 5, 2023
bee789c
ceac plot fixes to ggplot and plotly versions
andbe Dec 5, 2023
75b550f
added native plotly ceef plot
andbe Dec 6, 2023
271cbfd
added contour plotly option, fixed ggplot contour
andbe Dec 11, 2023
a4fcb95
added contour2 plotly option
andbe Dec 11, 2023
9416120
[minor] changed eib position argument to string
andbe Dec 11, 2023
3fe8096
fix red wtp area line colour
andbe Dec 15, 2023
41e62cd
Fixed eib plotly parameters and added plot.bcea plotly method
andbe Dec 15, 2023
bb93198
Add plotly version to ib.plot
andbe Dec 15, 2023
e7b55ff
Fix bug in contour.bcea
andbe Dec 18, 2023
39a84e0
updated documentation and ran checks
andbe Dec 18, 2023
17acdef
Moved plotly to Imports to avoid dependency check errors
andbe Dec 18, 2023
fe1f2b9
Update DESCRIPTION
andbe Dec 22, 2023
d552af8
Added CEriskav.plot plotly option
andbe Dec 30, 2023
22d64c2
Update Rbuildignore to ignore the CITATION.cff file
giabaio Jan 8, 2024
138cebf
Fixed bugs in ceef
andbe Feb 16, 2024
09f1042
fix pkgdown
andbe Feb 16, 2024
46f6488
Fix ceef.plot efficiency colors in base and ggplot
andbe Feb 16, 2024
1bf4e3b
Fixes for check() warnings and notes
andbe Feb 16, 2024
974b9a5
remove unused ... argument in CEriskav.plot
andbe Feb 16, 2024
53e2fe6
fix CEriskav check() warnings
andbe Feb 16, 2024
975cd65
Resolve merge conflict with dev
giabaio Feb 16, 2024
3416d68
Merge pull request #5 from andbe/dev
andbe Mar 8, 2024
bf104aa
Fix some partial matching
TimTaylor Mar 27, 2024
58548d8
Merge pull request #63 from TimTaylor/partial-matching
giabaio Mar 27, 2024
8c8eb9f
Merge branch 'main'
andbe Dec 10, 2024
9c063d9
Fixes to ceplane.plot parameters and documentation
andbe Dec 11, 2024
9d9b2c9
Fixes to plot.bcea plotly and plot.CEriskav
andbe Dec 12, 2024
c68e8da
Merge branch 'dev' into master
andbe Dec 12, 2024
b02557e
Minor fixes to the additional ggplot wtp options
andbe Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file added .httr-oauth
Empty file.
82 changes: 0 additions & 82 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Authors@R: c(
role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0003-4314-2570")),
person("Andrea", "Berardi",
email = "[email protected]",
email = "[email protected]",
role = c("aut"),
comment = c(ORCID = "0000-0002-2906-496X")),
person("Anna", "Heath",
Expand All @@ -28,6 +28,7 @@ Imports:
MASS,
Matrix,
MCMCvis,
plotly,
purrr,
Rdpack,
reshape2,
Expand All @@ -42,7 +43,6 @@ Suggests:
knitr,
markdown,
mgcv,
plotly,
plotrix,
RColorBrewer,
rjags,
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ S3method("setKmax<-",bcea)
S3method("setKmax<-",default)
S3method("setReferenceGroup<-",bcea)
S3method("setReferenceGroup<-",default)
S3method(CEriskav.plot,CEriskav)
S3method(bcea,bugs)
S3method(bcea,default)
S3method(bcea,rjags)
Expand Down Expand Up @@ -51,6 +52,7 @@ export("mixedAn<-")
export("setComparisons<-")
export("setKmax<-")
export("setReferenceGroup<-")
export(CEriskav.plot)
export(bcea)
export(best_interv_given_k)
export(ce_table)
Expand Down Expand Up @@ -94,6 +96,7 @@ export(validate_bcea)
import(dplyr)
import(ggplot2)
import(grid)
import(plotly)
import(reshape2)
importFrom(MASS,kde2d)
importFrom(MCMCvis,MCMCchains)
Expand All @@ -110,6 +113,7 @@ importFrom(grDevices,colors)
importFrom(grDevices,colours)
importFrom(grDevices,dev.new)
importFrom(grDevices,devAskNewPage)
importFrom(grDevices,gray)
importFrom(grDevices,grey.colors)
importFrom(grDevices,pdf.options)
importFrom(grDevices,ps.options)
Expand Down
51 changes: 51 additions & 0 deletions R/CEriskav.plot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#' @rdname CEriskav.plot
#'
#' @template args-he
#' @param pos Legend position
#' @param graph A string used to select the graphical engine to use for
#' plotting. Should (partial-)match the options `"base"`,
#' `"ggplot2"` or `"plotly"`. Default value is `"base"`.
#'
#' @return \item{plot}{ A ggplot or plot_ly object containing the plot. Returned only
#' if `graph_type="ggplot2"` or `graph_type="plotly"`.}
#' @seealso [bcea()]
#'
#' @references
#' \insertRef{Baio2013}{BCEA}
#'
#' @importFrom grDevices colours
#'
#' @export
#'
CEriskav.plot.CEriskav <- function(he,
pos = "topright",
graph = c("base", "ggplot2", "plotly")
) {

graph <- match.arg(graph)
# extra_args <- list(...)

if (is_baseplot(graph)) {
CEriskav_plot_base(he,
pos_legend = pos)
} else if (is_ggplot(graph)) {
CEriskav_plot_ggplot(he,
pos_legend = pos)
} else if (is_plotly(graph)) {
CEriskav_plot_plotly(he,
pos_legend = pos)
}
}

#' Cost-effectiveness Plot Including a Parameter of Risk Aversion (CEriskav)
#'
#' @template args-he
#' @param pos Legend position
#' @param graph A string used to select the graphical engine to use for
#' plotting. Should (partial-)match the options `"base"`,
#' `"ggplot2"` or `"plotly"`. Default value is `"base"`.
#' @export
#'
CEriskav.plot <- function(he, pos, graph) {
UseMethod('CEriskav.plot', he, pos, graph)
}
74 changes: 73 additions & 1 deletion R/CEriskav_plot_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @name CEriskav_plot_graph
#' @title Cost-effectiveness Plot Including a Parameter of Risk Aversion
#'
#' @description Choice of base R, \pkg{ggplot2}.
#' @description Choice of base R, \pkg{ggplot2} or \pkg{plotly}.
#'
#' @template args-he
#' @param pos_legend Legend position
Expand Down Expand Up @@ -159,3 +159,75 @@ CEriskav_plot_ggplot <- function(he, pos_legend) {
invisible(list(eib = eibr_plot,
evi = evir_plot))
}

#' @rdname CEriskav_plot_graph
#' @title CEriskav plotly version
#'
CEriskav_plot_plotly <- function(he, pos_legend) {
default_comp <- 1
linetypes <- rep(c(1,2,3,4,5,6), ceiling(he$R/6))[1:he$R]

# labels
text <- paste0("r = ", he$r)

# if the first value for r is small enough,
# consider close to 0 and print label accordingly
if (he$r[1] < 1e-8) text[1] <- paste("r","\U2B62","0")

legend_params <- make_legend_plotly(pos_legend)

eib_dat <-
melt(he$eibr[, default_comp, , drop = FALSE],
value.name = "eibr") |>
dplyr::rename(k = "Var1", r = "Var3") |>
dplyr::mutate(r = factor(.data$r, labels = text))

evi_dat <-
melt(he$evir,
value.name = "evir") |>
dplyr::rename(r = "Var2", k = "Var1") |>
dplyr::mutate(r = factor(.data$r, labels = text))

eibr_plot <-
plotly::plot_ly(data = eib_dat, linetype = ~r, x = ~k) |>
plotly::add_trace(
y = ~eibr,
type = "scatter",
mode = "lines",
linetypes = linetypes,
line = list(
color = "black"
)
) |>
plotly::layout(
title = "EIB as a function of the risk aversion parameter",
xaxis = list(title = "Willingness to pay"),
yaxis = list(title = "EIB"),
legend = list(title = list(text = "Risk aversion"))
) |>
plotly::config(displayModeBar = FALSE)

evir_plot <-
plotly::plot_ly(data = evi_dat, linetype = ~r, x = ~k) |>
plotly::add_trace(
y = ~evir,
type = "scatter",
mode = "lines",
linetypes = linetypes,
line = list(
color = "black"
)
) |>
plotly::layout(
title = "EVI as a function of the risk aversion parameter",
xaxis = list(title = "Willingness to pay"),
yaxis = list(title = "EVI"),
legend = list(title = list(text = "Risk aversion"))
) |>
plotly::config(displayModeBar = FALSE)

print(list(eibr_plot, evir_plot))

invisible(list(eib = eibr_plot,
evi = evir_plot))
}
2 changes: 1 addition & 1 deletion R/ceac.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#'
ceac.plot.bcea <- function(he,
comparison = NULL,
pos = c(1, 0),
pos = "bottomright",
graph = c("base", "ggplot2", "plotly"),
...) {
graph <- match.arg(graph)
Expand Down
24 changes: 9 additions & 15 deletions R/ceac_plot_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ ceac_ggplot <- function(he,

ggplot(data_psa, aes(x = .data$k, y = .data$ceac)) +
geom_line(aes(linetype = .data$comparison,
linewidth = factor(.data$comparison),
colour = factor(.data$comparison))) +
theme_ceac() +
theme_add + # theme
Expand All @@ -160,21 +159,15 @@ ceac_ggplot <- function(he,
#' @rdname ceac_plot_graph
#'
ceac_plot_plotly <- function(he,
pos_legend = "left",
pos_legend = "bottomright",
graph_params) {

comparisons_label <-
paste0(he$interventions[he$ref]," vs ",he$interventions[he$comp])

data.psa <- data.frame(
k = he$k,
ceac = he$ceac,
comparison = as.factor(c(
sapply(1:he$n_comparisons, function(x) rep(x, length(he$k)))
)),
label = as.factor(c(
sapply(comparisons_label, function(x) rep(x, length(he$k)))
)))
k = rep(he$k, he$ceac |> ncol()),
ceac = he$ceac |> c(),
comparison = he$ceac |> colnames() |> as.factor() |> as.numeric() |> sapply(function(x) rep(x, length(he$k))) |> c(),
single_label = he$ceac |> colnames() |> as.factor() |> sapply(function(x) rep(x, length(he$k))) |> c()
)
data.psa$label = paste0(he$interventions[he$ref], " vs ", data.psa$single_label)

graph_params$line$type <- graph_params$line$type %||% rep_len(1:6, he$n_comparisons)

Expand Down Expand Up @@ -214,7 +207,8 @@ ceac_plot_plotly <- function(he,
title = graph_params$annot$y,
range = c(0, 1.005)),
showlegend = he$n_comparisons > 1,
legend = legend_params)
legend = legend_params) |>
plotly::hide_colorbar()

plotly::config(ceac, displayModeBar = FALSE)
}
Expand Down
Loading
Loading