# Maraca Plots - Plotting win odds

## Component plot

The maraca package also contains an additional plot called `"component_plot"`. This one allows to plot the different components that make up the win odds calculation. More specifically, for each outcome, the plot shows how often patients in each treatment arm “won” against the other arm. For the time-to-event endpoints, this means counting how many patients of the other arm had no more prioritized event prior. For the continuous outcome this means counting how many patients had a lower value. The results are separated for each outcome (non-cumulative) and also include ties (patients from 2 treatment arms having same outcome at the same time/same continuous outcome value).

Let us first read in some data.

``````library(maraca)

data(hce_scenario_a)``````

In order to use the `component_plot`, we have to first create a `maraca` object. Important here is to set the argument `compute_win_odds = TRUE`, so that the necessary calculations are included.

``````maraca_dat <- maraca(
data = hce_scenario_a,
step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
last_outcome = "Continuous outcome",
fixed_followup_days = 3 * 365,
column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
arm_levels = c(active = "Active", control = "Control"),
# Make sure to calculate the win odds
compute_win_odds = TRUE
)``````

Now we can just plot the object using the `component_plot()` function.

``component_plot(maraca_dat)``

It is also possible to use the `component_plot()` function directly on an `hce` object (created using the hce package).

``````library(hce)

Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1)
Rates_P <- c(2.47, 2.24, 2.9, 4, 6)

hce_dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P,
CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3,
seed = 31337)

component_plot(hce_dat)``````

## Cumulative plot

Furthermore, there is a plot called `"cumulative_plot"`. Similar to the `component_plot`, this plot shows the different HCE components that make up the win odds calculation. Different to the component plot, this plot provides insight into the contributed effect for each of the components as they are added in sequence (from top to bottom). Additionally, there is also a right-hand panel that shows a forest plot with the win odds and win ratio corresponding to the same cumulative sequence. To understand the contribution from each outcome, we artificially set all the less prioritized outcomes as ties and calculate the win odds/ratio. Thus, for each added outcome there will be less ties.

As before, in order to use the `cumulative_plot`, we have to first create a `maraca` object. Important here is to set the argument `compute_win_odds = TRUE`, so that the necessary calculations are included.

``````maraca_dat <- maraca(
data = hce_scenario_a,
step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
last_outcome = "Continuous outcome",
fixed_followup_days = 3 * 365,
column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
arm_levels = c(active = "Active", control = "Control"),
# Make sure to calculate the win odds
compute_win_odds = TRUE
)``````

Now we can just plot the object using the `cumulative_plot()` function.

``cumulative_plot(maraca_dat)``

It is also possible to use the `cumulative_plot()` function directly on an `hce` object (created using the hce package).

``cumulative_plot(hce_dat)``

The user can also choose to only display one of the statistics (win odds or win ratio) by specifying so in the `include` parameter.

``cumulative_plot(maraca_dat, include = "win odds")``

The y-axis can easily be reversed using the `reverse` parameter.

``cumulative_plot(hce_dat, reverse = TRUE)``

## Styling

The resulting plot for the `component_plot()` functions is a normal ggplot2 object that can be styled accordingly.

``````component_plot(maraca_dat) +
ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL)``````

Note that the `cumulative_plot()` function is using the patchwork package to combine 2 ggplot2 objects - the bar plot and the forest plot that together make up the `cumulative_plot()`. They can be accessed as list items and styled accordingly.

``````p <- cumulative_plot(maraca_dat)
# Accessing the first ggplot2 object and adding styling (bar plot)
p[[1]] <- p[[1]] +
ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL)
p``````