
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!
The two lines are actually the x axis labels, but you can remove them with axis.text.x=element_blank():
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", axis.text.x=element_blank())

Alternatively, if you want to show the individual Names by setting to free_x in facet_wrap, then change the text size in theme. Though it is a lot of information to show on one graph and will be difficult to see.
pokemon %>%
select(Name, type_1, Attack, Defense) %>%
mutate(AttDefRatio = Attack/Defense) %>%
ggplot(
aes(Name, AttDefRatio)
) +
geom_point(size = 0.5) +
facet_wrap(type_1 ~ ., ncol = 5, scales = "free_x") +
theme(legend.position = "bottom", axis.text.x=element_text(angle = 90, vjust = 0.5, hjust=1, size = 3))

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:
coord_flip(), which is often a nice solution to long x axis labelsncol argument to facet_wrap()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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With