Aliases: ggnetworkmap
Keywords:
### ** Examples # small function to display plots only if it's interactive p_ <- GGally::print_if_interactive invisible(lapply(c("ggplot2", "maps", "network", "sna"), base::library, character.only = TRUE))
Error in FUN(X[[i]], ...): there is no package called 'network'
## Example showing great circles on a simple map of the USA ## http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/ ## No test: airports <- read.csv("http://datasets.flowingdata.com/tuts/maparcs/airports.csv", header = TRUE) rownames(airports) <- airports$iata # select some random flights set.seed(123) flights <- data.frame( origin = sample(airports[200:400, ]$iata, 200, replace = TRUE), destination = sample(airports[200:400, ]$iata, 200, replace = TRUE) ) # convert to network flights <- network(flights, directed = TRUE)
Error in network(flights, directed = TRUE): could not find function "network"
# add geographic coordinates flights %v% "lat" <- airports[ network.vertex.names(flights), "lat" ]
Error in network.vertex.names(flights): could not find function "network.vertex.names"
flights %v% "lon" <- airports[ network.vertex.names(flights), "long" ]
Error in network.vertex.names(flights): could not find function "network.vertex.names"
# drop isolated airports delete.vertices(flights, which(degree(flights) < 2))
Error in delete.vertices(flights, which(degree(flights) < 2)): could not find function "delete.vertices"
# compute degree centrality flights %v% "degree" <- degree(flights, gmode = "digraph")
Error in degree(flights, gmode = "digraph"): could not find function "degree"
# add random groups flights %v% "mygroup" <- sample(letters[1:4], network.size(flights), replace = TRUE)
Error in network.size(flights): could not find function "network.size"
# create a map of the USA usa <- ggplot(map_data("usa"), aes(x = long, y = lat)) + geom_polygon(aes(group = group), color = "grey65", fill = "#f9f9f9", size = 0.2) # overlay network data to map p <- ggnetworkmap( usa, flights, size = 4, great.circles = TRUE, node.group = mygroup, segment.color = "steelblue", ring.group = degree, weight = degree )
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
## Exploring a community of spambots found on Twitter ## Data by Amos Elberg: see ?twitter_spambots for details data(twitter_spambots) # create a world map world <- fortify(map("world", plot = FALSE, fill = TRUE)) world <- ggplot(world, aes(x = long, y = lat)) + geom_polygon(aes(group = group), color = "grey65", fill = "#f9f9f9", size = 0.2) # view global structure p <- ggnetworkmap(world, twitter_spambots)
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
# domestic distribution p <- ggnetworkmap(net = twitter_spambots)
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
# topology p <- ggnetworkmap(net = twitter_spambots, arrow.size = 0.5)
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
# compute indegree and outdegree centrality twitter_spambots %v% "indegree" <- degree(twitter_spambots, cmode = "indegree")
Error in degree(twitter_spambots, cmode = "indegree"): could not find function "degree"
twitter_spambots %v% "outdegree" <- degree(twitter_spambots, cmode = "outdegree")
Error in degree(twitter_spambots, cmode = "outdegree"): could not find function "degree"
p <- ggnetworkmap( net = twitter_spambots, arrow.size = 0.5, node.group = indegree, ring.group = outdegree, size = 4 ) + scale_fill_continuous("Indegree", high = "red", low = "yellow") + labs(color = "Outdegree")
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
# show some vertex attributes associated with each account p <- ggnetworkmap( net = twitter_spambots, arrow.size = 0.5, node.group = followers, ring.group = friends, size = 4, weight = indegree, label.nodes = TRUE, vjust = -1.5 ) + scale_fill_continuous("Followers", high = "red", low = "yellow") + labs(color = "Friends") + scale_color_continuous(low = "lightgreen", high = "darkgreen")
Error in require_namespaces(c("network", "sna")): please install the package 'network'. install.packages('network')
p_(p)
Error in print(p): object 'p' not found
## End(No test)