'Why are these solid lines appearing below my plot in ggplot?

enter image description here

Here is my code:

pokemon <- read_csv("https://uwmadison.box.com/shared/static/hf5cmx3ew3ch0v6t0c2x56838er1lt2c.csv")

pokemon %>%  
  select(Name, type_1, Attack, Defense) %>% 
  mutate(AttDefRatio = Attack/Defense) %>% 
  ggplot(
    aes(Name, AttDefRatio)
  ) +
  geom_point(size = 0.5) +
  facet_wrap(type_1 ~ .) +
  theme(legend.position = "bottom")

for this home work assignment we are working with faceting, and everything pretty much looks how it should, but there those two thick lines at the bottom of the plot. If anyone has any idea why its happening that would be awesome!



Solution 1:[1]

Those are your x axis labels. The labels are much longer than the available space after faceting, so they’re overlapping into a big jumble.

Possible solutions:

  • use coord_flip(), which is often a nice solution to long x axis labels
  • recode the x variable labels to be shorter
  • facet to fewer columns using the ncol argument to facet_wrap()
  • reduce the number of facets by collapsing or removing groups with few cases

I think your issue is compounded by every Pokémon name being repeated for each facet column, even though only a subset actually appears in each facet. You can fix this by setting scales = "free_x" within facet_wrap(), so that only labels included in each facet will be included.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1