I am trying to add a regression line in a facet grid graphs, but only in the first line.
When I use the function geom_smooth() all graphs appear with the regression line.
I tryied to insert a "if" funtion, but gets me an error message.
Here is my code:
p <- ggplot(datar, aes(x = Ano, y = area_taxa,group = usos)) +
geom_line(aes(color = usos), size = 1) +
geom_smooth(method="lm", size = 0.8, lty = "dashed", color = "red") +
theme(legend.position = "none") +
theme(axis.text.y = element_text(size = 18, color = "black"),
axis.text.x = element_text(size=15, color = "black"),
axis.title.x = element_text(size = 20),
axis.title.y = element_text(size = 20),
legend.text = element_text(size=20),
strip.text.x = element_text(size = 18),
strip.text.y = element_text(size = 18)) +
labs(x = "Year", y = "") + ggtitle("") +
facet_grid(tipo_f~usos_f, scales = "free_y")+
scale_x_continuous(breaks = seq(1985,2020,10))
Thanks!! It worked too!! But now I am trying to break Y axis, to gave a better resolution, I am trying to find in google but still nothing, can you help me again, please?
I'd like to break just the second line of graphs.
Actually the initial example was incomplete, this one is the final plot. The broken axis is something I can try latter. Thank you very much for your help!!