如何在R中的地理图上绘制网络?

时间:2018-06-26 12:44:58

标签: r spatial

enter image description here

嗨,我想获得一个像attach这样的空间网络,但是我不知道该怎么做,我尝试了ggplot,ggraph,igraph,但效果不佳。

有人可以分享一些密码或给我一些建议吗?

1 个答案:

答案 0 :(得分:0)

我尝试了ggplot2方法,但出现了错误(FUN(X [[i]],...)中的错误:找不到对象'to.lon')。

ggplot(chicken_QH, 
       aes(x = from.lon, y = from.lat, xend = to.lon, yend = to.lat)) +
  geom_edges(aes(size = chickenBatchs/10000, 
                 alpha = chickenBatchs/10000,
                 color = type),
             curvature = 0.3,
             arrow = arrow(length = unit(10, "pt"), 
                           type = "closed")) +
  geom_nodes(color = "gold", size = 10, alpha = .5) +
  geom_nodes(color = "gold", size = 3) +
  geom_nodetext(aes(label = from), fontface = "bold") +
  scale_linetype_discrete(guide = F) +
  geom_polygon(data = china_blank, 
               aes(x = long, y = lat, group = group),
               fill = "white",
               col = "grey",
               size = rel(.3)) +
  coord_quickmap()

也可以使用基本绘图方法,尽管它确实可以工作,但是它的位置很简单。

map(china_blank, asp = 1)
plot(dg_cattle_QH, 
     edge.color = adjustcolor(qc, alpha.f = .7),
     edge.curved = 0.2,
     edge.width = qw,
     vertex.size = 6,
     vertex.color = adjustcolor("gold", alpha.f = .7),
     layout = as.matrix(xy_province_capital_ch[, 3:4]), 
     add = TRUE, 
     rescale = FALSE)

enter image description here