0

I have an air pollutant that comes from 4 different sources so I have made 4 plot to show the amount of air pollutant across the years to see whether it increased or decreased specifically for Baltimore city and I found that the POINT type is the only one that increased so I want to make the regression line of it red so in general how to edit a plot in such a case ?

Here is the plot

here is the plot

here is a sample of the data frame :

   type     year      emissions
1  NON-ROAD 1999      522.94000
2  NON-ROAD 2002      240.84692
3  NON-ROAD 2005      248.93369
4  NON-ROAD 2008       55.82356
5  NONPOINT 1999     2107.62500
6  NONPOINT 2002     1509.50000
7  NONPOINT 2005     1509.50000
8  NONPOINT 2008     1373.20731
9   ON-ROAD 1999      346.82000
10  ON-ROAD 2002      134.30882
11  ON-ROAD 2005      130.43038
12  ON-ROAD 2008       88.27546
13    POINT 1999      296.79500
14    POINT 2002      569.26000
15    POINT 2005     1202.49000
16    POINT 2008      344.97518



ggplot(Baltimore , aes(years,emissions)) + 
 geom_point() +
 facet_wrap(.~ Baltimore$type) +
 geom_smooth(method = "lm" , se=FALSE ,col = "green"  ) +
 ggtitle("emission across years splited by source type" ) 
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions.The data you shared doesn't even have any values for POINT. Also it seems like the column names might not match up. – MrFlick Aug 13 '19 at 19:15

1 Answers1

0

This should do it, let me know if you run into errors

ggplot(Baltimore , aes(years,emissions)) + 
  geom_point() +
  geom_smooth(method = "lm" , se=FALSE ,aes(col = ifelse(type == "POINT",F,T)),show.legend = FALSE)+
  facet_wrap(.~ Baltimore$type) +
  scale_color_manual(values=c("red","green"))
  ggtitle("emission across years splited by source type" ) 

Yazid
  • 101
  • 1
  • 4