I want to represent 2 ships on a map in an interactive way (leaflet based method) with some of their metadata as well. Naturally, metadata of a ship usually contains the heading of the vessel and the most digestible way to represent is by rotating the symbol of the point data accordingly.
After some first trials, I managed to recreate it by following icon rotation in leaflet package, using sheer leaflet and a plugin that allowed me to write in smooth syntax like rotationAngle=~T_heading
. This way's result looks like below.
However, I am searching for a way to use sf and tmap packages as syntax (tmap's interactive view is also leaflet based) since they are much more complete and sophisticated frameworks for managing and visualizing geospatial information.
Let's again recreate the sample data of the two vessels and plot them.
aship<-c(23.622333,37.937489,'Santa Maria',8,300)
bship<-c(23.621303,37.937430,'Vancouver CC',10,35)
shipdata<-data.frame(rbind(aship,bship))
colnames(shipdata)<-c('long','lat','VesselName','sog','T_heading')
shipdata$long<-as.numeric(as.character(shipdata$long))
shipdata$lat<-as.numeric(as.character(shipdata$lat))
shipdata$sog<-as.numeric(as.character(shipdata$sog))
shipdata$T_heading<-as.numeric(as.character(shipdata$T_heading))
#Simple features transformation
ship_sf<-shipdata%>%
st_as_sf(coords=c('long','lat'))%>%
st_set_crs(4326)
# Use tmap and plot the vessels using a vessel_icon of my own
map_s1<-tm_basemap(leaflet::providers$OpenStreetMap)+
tm_shape(ship_sf)+
tm_markers(shape = vessel_icon)+
tm_view(set.view=c(lon=23.622333,lat=37.937489,zoom=17))
Up until now I haven't found a way to rotate markers in a tmap way. Is there any simple solution i am missing out?
Much appreciated