One label does not show up in geom_label_repel

I am using geom_label_repel to add country labels to my scatterplot. However, when using it to only show certain countries, it works for some but not all of them. See figure below. Here is my code:

ggplot(gft_k_im[gft_k_im$c_gft_k < quantile(gft_k_im$c_gft_k, c(.99)) & partner == "DEU"], aes(x=imp_sha, y=c_gft_k)) + 
    xlim(0, 27) +
    ylim(0, 6.2) +
    geom_point(alpha=0.3, aes(size=imports, color=continenta)) + 
    theme_ipsum() +
    labs(title="GFT vs. Imports Germany", x="Import Share (in %)", y = "Change in GFT (in %)") +
    labs(size = "Imports (in bn.)", color = "Continent") +
    geom_smooth(method=lm,se=FALSE) +
    geom_label_repel(aes(label = ifelse(country == c("FRA", "USA"),as.character(country),'')), min.segment.length = 0,
                  box.padding   = 0.1, 
                  point.padding = 0.5,
                  segment.color = 'grey50', 
                  xlim = x_limits, ylim = c(-Inf, Inf))

As you can see, for USA and FRA it works well. However, when I select "CHN" then China does not show up even though it's in the data and can be displayed when using labeling techniques different from geom_label_repel. Why is that?

Hi,

I do not see the "CHN" filter in your code. Also, I'm not able to test your code since this is not a valid reprex. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

Grtz,
PJ

Yes it might be difficult to create a reprex as the issue might be due to overlapping bubbles for example. The problem only arises for some countries so when running the same code with "CHN" included in addition to "USA" and "FRA" none of the labels show up. So I was hoping someone would know why that could be the case.

Hi,

Yes that was indeed one of my toughts. The geom_label_repel function has an argument "max.overlaps" which states:

max.overlaps
Exclude text labels that overlap too many things. Defaults to 10.

So it might be that's the reason it's not shown in certain cases, but I'm not sure if I can't try.

Hope this helps,
PJ

Hi!

yes I thought about that too and so I adjusted the max.overlaps to 0 as well as 1000 to see if it changes anything but unfortunately it doesn't. I also experimented with other parameters but couldn't make it work. I will see whether I can come up with a reprex.

Best,
N