I'm having trouble finding a way to repel text labels in one facet grid "Mountain"(top-center). All other state labels are clear enough to distinguish, but I can't figure out how to move around the state labels in "Mountain" without affecting other grids.
I've tried using:
geom_text_repel(force = x)
But I don't know of any to force the code to affect only a single grid. Below is my code along with the output. My desired outcome is to have the states in "Mountain" grid to appear like they do in "West North Central" or something that can be read easily.
Another thing I haven't quite figured out is my x axis labels. I included the annual range to be 2010 to 2018, to allow space for the state labels, but I only want the axis to show 2010 to 2017 years.
Code/output:
p2 + xlim(breaks = seq(2010,2017, by = 1))
Error in limits.numeric(c(...), "x") : length(lims) == 2 is not TRUE
Any suggestions?
p <- ggplot(plotflow, aes(x = YEAR, y = Y, group = STATE)) +
theme_bw() +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank()) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))
p0 <- p + geom_point(color = "gray70")
p1 <- p0 + geom_smooth(mapping = aes(group = STATE),
se = F, color = "gray10")
p2 <- p1 + geom_text_repel(data = subset(dataplot, YEAR == max(YEAR)),
mapping = aes(x = YEAR, y = Y, label = ALPHA_CODE),
size = 3.6, segment.color = NA, nudge_x = 40) + coord_cartesian(c(min(dataplot$YEAR), 2018))
p2 + labs(x = "Year") +
facet_wrap(CENSUS_DIVISION ~ ., nrow = 3)