Skip to content

Instantly share code, notes, and snippets.

@aarong1
Created October 25, 2021 18:45
Show Gist options
  • Save aarong1/c697c38e5cf8c476885cf9b49d82aa31 to your computer and use it in GitHub Desktop.
Save aarong1/c697c38e5cf8c476885cf9b49d82aa31 to your computer and use it in GitHub Desktop.
display the graph transmission network as a geospatial figure.
leaflet(geo_lines)%>%
addTiles()%>%
addPolylines(stroke = 'blue',color = 'black',
weight = 1,opacity = 1,fill = 'green',
fillOpacity = 1,dashArray = 17)
nodes_sub <- igraph::as_data_frame(graph_tot_sub,what='vertices')
ed <- igraph::as_data_frame(graph_tot_sub,what='edges')
ed <- ed%>%filter(label!='15997')%>%
rownames_to_column(var='group')%>%
pivot_longer(c(to,from))
plotHH <- nodes_sub%>%select(value=name,x=Latitude,y=Longitude)%>%
left_join(ed,.)%>%add_count(group,x,y)%>%filter(n==2)
ed1 <- nodes_sub%>%select(value=name,x=Latitude,y=Longitude)%>%
left_join(ed,.)%>%add_count(group,x,y)%>%filter(n!=2)
ed2 <- ed1%>%
select(y,x)%>%
split(.,ed1$group)%>%
lapply(as.matrix)%>%
lapply(FUN = function(x){colnames(x) = NULL;return(x)})
names(ed2)=NULL
x <- leaflet()%>%
addTiles()
if(length(ed2)!=0){
plot_con <- map2(ed2,as.character(1:length(ed2)),~Lines(Line(.x),ID=.y))%>%#list()%>%#class#View
#map(.f = ~sp::spTransform(.x,CRSobj = CRS("+init=epsg:4326")))%>%
SpatialLines()#%>%
names(plot_con)=NULL
x <- x%>%
addPolylines(#lng = ~y,lat=~x,
data = plot_con,
stroke = 'blue',
color = 'purple',
weight = 1,
opacity = 0.5)
}else{x%>%leaflet::flyTo(-6.5,54.6,7)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment