Problem with geom_text_repel

Hello everyone! I'm beginner in R.
Today, I wanted to make a plot of pubs in UK, but it always gives me mistake in aesthetics...
My goal is to make this:


where 40 or 50 most frequent names of pubs in the UK: the x-axis is for the number of symbols in the pub name, the y-axis is for the number of bars with the same name.
I made this as variables:

bars <- read_csv("https://raw.githubusercontent.com/dashapopova/Intro-to-R/main/HWs/HW2/UK_pubs.csv")
bars
pubs <- count(bars, pub_name, sort = TRUE) 
pubs_sl <- slice(pubs, n = 1:40)
pub_len <- pubs_sl %>% 
  mutate(n_charactars = str_count(pub_name))

But I cant integrate them in the plot without a mistake in aesthetics . Can you tell me why I have this mistake with this variables?

Thank you for your answers!

This works for me:

ggplot(pub_len,
       aes(x = n_charactars, y = n)) +
  geom_point() +
  ggrepel::geom_text_repel(aes(label = pub_name))

I do get a warning:

Warning message:
ggrepel: 13 unlabeled data points (too many overlaps). Consider increasing max.overlaps 

But that doesn't prevent successful plotting (it's a warning, not an error). It's just telling me that there are too many names overlapping so it can't write all the names. I can force writing all the labels either by increasing plot size or by changing max.overlaps (but that makes the plot hard to read):

ggplot(pub_len,
       aes(x = n_charactars, y = n)) +
  geom_point() +
  ggrepel::geom_text_repel(aes(label = pub_name), max.overlaps = Inf)

If it's a different error message that you have, you'll need to share your code and the exact error message so that we can help.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.