Hello everyone,

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))

I tryied the add:

if(tipo_f = "(A) Land use (Mha)"){

geom_smooth(method="lm", size = 0.8, lty = "dashed", color = "red")}

I also need the equations to be shown in the graphs.

Can someone help me please?!