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

Duplicate text labels after ggbreak #63

Open
willizhang opened this issue Dec 2, 2023 · 1 comment
Open

Duplicate text labels after ggbreak #63

willizhang opened this issue Dec 2, 2023 · 1 comment

Comments

@willizhang
Copy link

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")
image

Thank you very much in advance for your time and help!

Best regards,
Willi

@GuangchuangYu
Copy link
Member

see also #56.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants