I encountered a problem showing the bars with a value of zero, so I would like to set the starting point of the y-axis as 5, since the values are negative.
Here is my code.
p4 <- ggplot(path_response, aes(y= resp,x = reorder(Patient, Path_response), fill = response)) +
geom_col() +
scale_fill_manual(values = c("pink", "brown1","brown4")) +
ggnewscale::new_scale_fill()+
geom_col(aes(y =15, fill = Regimen), width = 0.9) +
geom_col(aes(y = 10), fill = "white", color = "white") +
geom_text(aes(y = 7, label = Patient), size = 4, fontface = "bold") +
scale_fill_brewer(palette = "Set1")+
theme_classic()+
theme(axis.line.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_text(size=16, "bold"),
legend.text = element_text(size= 14, "bold"),
legend.background = element_blank(),
legend.box.background = element_rect(color = "black") # add frame to the legend
) +
labs(y="Pathological Response (%)", x="")
Here is my data for trying.
path_response <- tibble::tribble(
~Patient, ~Regimen, ~response, ~Path_response, ~resp,
"129", "Nivo/Rela", "pMR", -100L, -100,
"113", "Nivo/Ipi", "pMR", -90L, -90,
"131", "Nivo/Rela", "pMR", -90L, -90,
"108", "Nivo/Ipi", "pMR", -80L, -80,
"139", "Nivo/Rela", "pMR", -80L, -80,
"104", "Nivo/Ipi", "pMR", -70L, -70,
"138", "Nivo/Rela", "pMR", -50L, -50,
"112", "Nivo/Rela", "pmR", -40L, -40,
"111", "Nivo/Rela", "pmR", -30L, -30,
"119", "Nivo/Ipi", "pmR", -30L, -30,
"141", "Nivo alone", "pmR", -20L, -20,
"102", "Nivo alone", "pmR", -10L, -10,
"103", "Nivo/Rela", "pmR", -10L, -10,
"106", "Nivo/Rela", "pmR", -10L, -10,
"109", "Nivo/Rela", "pmR", -10L, -10,
"114", "Nivo/Rela", "pmR", -10L, -10,
"121", "Nivo alone", "pmR", -10L, -10,
"133", "Nivo alone", "pmR", -10L, -10,
"134", "Nivo/Ipi", "pmR", -10L, -10,
"140", "Nivo/Ipi", "pmR", -10L, -10,
"143", "Nivo/Rela", "pmR", -10L, -10,
"101", "Nivo/Ipi", "NR", 0L, 0,
"107", "Nivo alone", "NR", 0L, 0,
"116", "Nivo alone", "NR", 0L, 0,
"117", "Nivo/Ipi", "NR", 0L, 0,
"123", "Nivo/Ipi", "NR", 0L, 0,
"124", "Nivo/Ipi", "NR", 0L, 0,
"125", "Nivo/Rela", "NR", 0L, 0,
"128", "Nivo alone", "NR", 0L, 0,
"130", "Nivo alone", "NR", 0L, 0,
"136", "Nivo alone", "NR", 0L, 0,
"137", "Nivo alone", "NR", 0L, 0,
)
However, when I tried different ways to change the y-axis ranges, it would flip the bars or change the bar formats. I appreciate any help.