YuLab-SMU / ggbreak

:broken_heart: An implementation of scale functions for setting axis breaks of a 'gg' plot.
https://www.frontiersin.org/articles/10.3389/fgene.2021.774846
129 stars 4 forks source link

Text is double printed with ggbreak when using geom_repel_text #56

Open johnnl15 opened 1 year ago

johnnl15 commented 1 year ago

Hi, i'm having this issue where the text is printed twice. Would appreciate advice on how to get around this:

require(ggplot2 ) require(ggbreak) require(ggrepel) set.seed(2019-01-19) d <- data.frame( x = 1:20, y = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22) )

d$label<-"hello" d$label[d$x!=7]<-NA p <- ggplot(d, aes(x, y,label=label)) + geom_point() + geom_text_repel()+ scale_y_break(c(7, 17 )) print(p)

image

phancanhtrinh commented 1 year ago

I have the same problem. Can anyone know how to solve this? Thank you very much

shanshenbing commented 1 year ago

I get same issue. Any help will be appreciated.

jmburgos commented 1 year ago

Same issue here. :)

jamiahuswalton commented 1 year ago

I am getting the same issue here. Any help would be greatly appreciated. I really like geom_repel_text better than geom_text.

Any help would be greatly appreciated!

pormr commented 10 months ago

Unlike ordinary facetting function, ggbreak seems to take a different approach to splitting axes, which is incompatible with ggrepel. However, you can still use facet_grid() with space = "free_*" and scales = "free_*" to split the plot while preventing the same labels from appearing twice:

p <- ggplot(d, aes(x, y)) +
  geom_point() +
  geom_blank(data = data.frame(x = Inf, y = c(7, 17))) +
  geom_text_repel(aes(label = label)) +
  facet_grid(vars(y <= 7), space = "free_y", scales = "free_y") +
  theme(strip.background = element_blank(),
        strip.text = element_blank())

print(p)

image

Tips: geom_blank can sometimes be useful, especially when you want to extend the limit of axes.