ggbreak
ggbreak copied to clipboard
Duplicate text labels after ggbreak
Hi,
Thank you very much for this nice package. I am trying to draw some plots but come across one issue:
- After ggbreak, the labels become duplicated at the right bottom of the graph.
library(ggalluvial)
library(ggplot2)
library(ggrepel)
library(ggbreak)
titanic_wide <- data.frame(Titanic)
titanic_long <- to_lodes_form(titanic_wide, axes = 1:4,
key = "variable", value = "value", id = "cohort",
diffuse = Class)
ggplot(
data = titanic_long,
aes(x = variable, stratum = value, alluvium = cohort, y = Freq)
) +
geom_alluvium(aes(fill=Class)) +
geom_stratum(aes(fill=Class)) +
scale_y_break( c( 50, 500 ), scales = 10, space = 0.3 ) +
geom_text(stat = "stratum", aes(label = after_stat(stratum)) ) +
theme_minimal() +
ggtitle(
"passengers on the maiden voyage of the Titanic",
"stratified by demographics and survival"
)+
scale_fill_manual(
values=c("red","orange","green","blue"),
breaks=c("1st","2nd","3rd","Crew"),
labels=c("1st","2nd","3rd","Crew"),
na.value = NA,
aesthetics = c("fill", "color")
) +
geom_text_repel(stat = "alluvium",
aes(x = as.integer(variable) + 0.15,
color = Class,
label = ifelse(variable == "Survived" & Freq >= 10, Freq, NA)),
direction = "y", nudge_x = .5,
point.padding = 0,
hjust = "left")
Thank you very much in advance for your time and help!
Best regards, Willi