Create an interactive map to explore your data.
When analyzing tracking data in R, you may want to explore the locations. One option is to export the cleaned data set and open it a GIS program. However, R also offers interactive mapping features. In this post, I’ll walk you through the steps I used to create interactive maps with my GPS data.
For the exercises, test data is from masked boobies.
To access the data you have to install the package sula: devtools::install_github(“MiriamLL/sula”)
library(sula)
Data_1original<-GPS_preparado
The function fortify helps the data frame to be more easily be plotted.
Data_2fortify<-fortify(Data_1original)
Make sure your lat and lon are numerical
Data_2fortify$lat<-as.numeric(Data_2fortify$Latitude)
Data_2fortify$lon<-as.numeric(Data_2fortify$Longitude)
Transform to spatial.
Select which CRS you will like to use.
Select the columns that are of interest.
Data_4info<-Data_3spatial[,c("IDs","trip_number","dia_hora")]
Install the package tmap.
This package allows you to create interactive maps.
For making the map interactive, the mode view should be declared.
tmap_mode("view")
To create your map with points you can use the arguments tm_shape and tm_dots
To rename the information that shows, you can add the argument popup.vars
To separate between individuals you can also include them as separated layers.
Using you can zoom-in to see the points.
Using you can zoom-out to see the points.
Using you can select which layers to show.
Put the cursor on top of the dot , when appears click on it and you should be able to see the ID, trip number and dt and time of the point.
Using tmap might save you the step to export your dataframe, and the import it into another program, particularly if you want to check a particular point and particular information associated to that point.