clgogl.blogg.se

Netmap example
Netmap example




netmap example

The plot itself, it is based on two different data sources, the sf object and the data frame produced by ggnetmap, the latter overlayed to the former. Since both identifiers are included, it is rather straightforward to add further variables by merging with other data frames. It will contain both vertex identifiers (from the network and the sf object), the coordinates of the edge’s start (which will coincide with the vertex identifier) and the coordinates of the edge’s end. The data frame returned by ggnetmap will describe the edges of the network, from which vertex information can also be derived. Elements of the sf objects are called features (i.e. a city, a state of a country), while network objects have vertices (the elements that may or may not be linked to each other) and edges (the connections between the vertices).įortified_df = ggnetmap(net, map, lkp_tbl, m_name= "spatial_id", n_name= "vertex.names") ggplot() + geom_sf( data=map) + #this will be the map on which the network will be overlayed geom_edges( data=fortified_df, aes( x=x, y=y, xend=xend, yend=yend), colour= "red") + #network edges geom_nodes( data=fortified_df, aes( x=x, y=y)) + #network vertices geom_nodetext( data=fortified_df, aes( x=x, y=y, label = spatial_id), fontface = "bold") + #vertex labels theme_blank() It will work with network objects as produced by either the network or the igraph package, without the need to specify the object class. The netmap package doesn’t attempt to reinvent the wheel, so it uses both the sf package to handle spatial data files (from shapefiles to KML files to whatnot) and the ggnetwork package to plot network data using ggplot2’s grammar of graphics.

netmap example

This may make the network more understandable, though not necessarily easier to read. When vertices already have a spatial component, though, a “natural” visualization is just to plot the vertices in their spatial position and display the edges between them. Network visualization is hard and most methods to visualize a network focus on displaying vertices and edges (loosely speaking, units of the network and relationships between them, respectively) in a way that highlights the properties of the network itself. Some data sets are both: relational data sets (networks) can be about units that have an inherent spatial aspect - trade networks between regions, relationships between users for which location data is available, traffic relationships between areas and so on. Other data sets have a geographical, spatial component: each unit represents a part of the physical world, like a river, a city, a country, a landmark. Some data sets are relational data sets, they represent relations between their units and which unit is connected to which ones, with a wide range of reasons for two units to be considered linked or not (family/kinship, trade, membership in a club etc.).






Netmap example