-1

I've got this data with latitude and longitude of some cities from southeast of Brazil, by year. I would like to plot these cities with red dots it in different maps. My data starts in 1996 and ends in 2018, so I need 23 maps of the southeast region. How can I do that, using R?

nome                estado   ano latitude longitude
  <chr>               <chr>  <dbl>    <dbl>     <dbl>
1 Abadia dos Dourados MG      2010    -18.5     -47.4
2 Abadia dos Dourados MG      2011    -18.5     -47.4
3 Abadia dos Dourados MG      2007    -18.5     -47.4
4 Abadia dos Dourados MG      2006    -18.5     -47.4
5 Abadia dos Dourados MG      2005    -18.5     -47.4
6 Abadia dos Dourados MG      2008    -18.5     -47.4
Mateus Maciel
  • 91
  • 1
  • 1
  • 6
  • Does this answer your question? [Plot coordinates on map](https://stackoverflow.com/questions/23130604/plot-coordinates-on-map) – understorey May 21 '20 at 16:34

1 Answers1

1

First you should convert the whole df into shapefile.

library(sp)    

coordinates(df) <- ~longitude+latitude

proj4string(df) <- CRS("+proj=longlat +datum=WGS84")

After that you can filter the sf by year using "for", "which" or any other funciton that you like.

Brutalroot
  • 146
  • 1
  • 7
  • 1
    But, how can I plot the maps? – Mateus Maciel May 21 '20 at 17:24
  • 1
    As i can see you want to plot those dots in different maps. You will need to load the shapes on R using the 'shapefile' function from 'raster' package. This topic will help you teaching how to plot 2 shapes in the same graph -> [link](https://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r) – Brutalroot May 21 '20 at 17:43