I am creating a stacked barplot showing different types of treatment for ovarian cancer. Each 'bar' represents a different treatment. Some patients are treated with the same combinational therapy, but not neccessarily in continued lines.
I've looked at this answer # 2.
But it doesn't cut it.
I've attached a sample patient
record_id line treatment value
134 47 1 Carboplatin og Docetaxel 1
135 47 2 Carboplatin og Caelyx 1
136 47 3 Carboplatin og Caelyx 1
137 47 4 AVANOVA, arm 2 - Bevacizumab og NIraparib 1
138 47 5 Carboplatin og Caelyx 1
Using the following ggplot for the patients generates
library(tidyverse)
library(ggplot2)
stack %>%
ggplot(aes(x = record_id, y = value, fill = interaction(treatment,-line))) +
geom_bar(stat = "identity", position = "stack", data = stack %>% filter(record_id == 47)) +
guides(fill = guide_legend("ordering"))
I have also tried using the fill = reorder
- same code as above. The result is
I was hoping to get a result looking the the first picture (with fill = interaction
), but where the colors appear the same for the same treatment (in this example 'Carboplatin and Caelyx').