I have been searching how to wrap text. It seems there should be a way to use labeller = label_wrap_gen(3) but I keep getting an error: --- Error in margins(vars, margins) : unused argument (margins)
Here is part of my code:
#simpson by protected status for domain FKNMS
ggplot(data = fk_strata_abun_diversity, aes(x = YEAR)) +
geom_point(aes(y = strata_simpson, color = "strata_simpson"),color = "blue") +
geom_line(aes(y = strata_simpson, color = "strata_simpson"), color = "blue") +
facet_grid(STRAT ~ protected_status,
labeller = labeller(.rows = strata_names, .cols = protected_status_names),
label_wrap_gen(width = 2)) + #error: in margins(vars, margins) : unused argument (margins) ??
labs(x = "Year", y = "Effective Number of Species") +
ggtitle("Simpson Diveristy of Reef Fish in the Florida Keys by Strata") +
theme(plot.title = element_text(hjust = 0.5, face = 'bold', size = 12)) +
scale_x_continuous(limits = c(1999, 2016), breaks = c(1999:2016)) +
scale_y_continuous(limits= c(0, 25), breaks = c(5,10,15,20,25))
Thank you in advance for the help
I found labeller = labeller(label_wrap_gen(width = 2
... does not wrap.
Try
facet_grid(STRAT ~ protected_status,
labeller = label_wrap_gen(width = 2, multi_line = TRUE))
the following will work for facet_grid()
and facet_wrap()
:
facet_grid(labeller = labeller(facet_category = label_wrap_gen(width = 16)))
where facet_category
is the faceting variable to modify and width
sets the maximum number of characters before wrapping.
multi_line
is only needed if you have specified multiple factors in your faceting formula (eg. ~first + second
)
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