首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建我的数据的地铁地图可视化

如何创建我的数据的地铁地图可视化
EN

Stack Overflow用户
提问于 2015-10-14 05:50:55
回答 1查看 1.6K关注 0票数 3

在一篇论文(http://www.ncbi.nlm.nih.gov/pubmed/25626705)中找到了下面这张漂亮的图。它可视化了不同实验室的工作流程,并很好地说明了它们的分歧之处。可以看到这对许多其他数据集也很有用。

有没有工具可以方便地从一组数据中创建这些类型的地图(即避免我必须从头开始在绘图应用程序中绘制这些地图)?

我可以在ggplot2中做这样的事情吗?

EN

回答 1

Stack Overflow用户

发布于 2017-10-05 11:11:44

这是我对公共汽车站地图的建议(在末尾有一个附图):

代码语言:javascript
复制
library(ggplot2)

# DF
datos <- data.frame(origen=c(rep("Ruta 126", 7), rep("Ruta 131", 6), rep("Ruta 132", 6)), 
                destino=c("San José", "Jericó", "Guadarrama", "San Juan Norte", "San Juan Sur", "Río Conejo", "Loma Larga",
                          "Cartago", "Copalchí", "El Alumbre", "San Juan Norte", "San Juan Sur", "Loma Larga",
                          "San Juan Norte", "Calle Valverde", "Calle Abarca", "San Juan Sur", "Río Conejo", "Loma Larga"),
                subsidio=c("","-345","-135","-400","-325","-155","400", "", "230", "255", "515", "530", "2150", rep("",6)))

# Levels to factor
datos$destino <- factor(datos$destino, levels = c("San José", "Cartago","Jericó", "Copalchí", "Guadarrama", "El Alumbre", "San Juan Norte",  "Calle Valverde", "Calle Abarca", "San Juan Sur", "Río Conejo", "Loma Larga"))
datos$origen <- factor(datos$origen, levels = c("Ruta 126", "Ruta 132", "Ruta 131"))

# Groups for geom_text
etiqueta1 <- c("San José", "Cartago","Jericó", "Copalchí", "Guadarrama", "El Alumbre", "Calle Valverde", "Calle Abarca", "Río Conejo")
etiqueta2 <- c("San Juan Norte", "San Juan Sur", "Loma Larga")

# group for geom_label
text1 <- c("-345","-135","-400","-325","-155","400")
text2 <- c("230", "255", "515", "530", "2150")

# Plot
ggplot(datos, aes(destino, origen, group=origen)) +
  geom_line(size=10, aes(color=origen)) +
  geom_segment(aes(x=7, xend=7, y= 1, yend=3), size=1, color="grey20", linetype=3) +
  geom_segment(aes(x=10, xend=10, y= 1, yend=3), size=1, color="grey20", linetype=3) +
  geom_segment(aes(x=12, xend=12, y= 1, yend=3), size=1, color="grey20", linetype=3) +
  geom_segment(aes(x=11, xend=11, y= 1, yend=2), size=1, color="grey20", linetype=3) +
  geom_point(size=6) +
  scale_color_manual("", values = c("steelblue3", "tomato2", "forestgreen")) +
  geom_text(data= subset(datos, destino %in% etiqueta1), aes(label=destino), nudge_y = .25, size=3, angle=45, fontface="bold") +
  geom_text(data= subset(datos, destino %in% etiqueta2 & origen== "Ruta 126"), aes(label=destino), nudge_y = -.2, size=4, fontface="bold") +
  geom_label(data= subset(datos, subsidio %in% text1 & origen== "Ruta 126"), aes(label=subsidio), nudge_y = -.5, size=4, fontface="bold") +
  geom_label(data= subset(datos, subsidio %in% text2 & origen== "Ruta 131"), aes(label=subsidio), nudge_y = .52, size=4, fontface="bold") +
  labs(x="", y="") +
  theme_minimal() +
  theme(panel.grid = element_blank()) +
  theme(axis.text = element_blank()) +
  theme(legend.text = element_text(size = 14)) +
  theme(legend.position = "bottom") + 
  guides(color = guide_legend(nrow=3, reverse = T)) +
  theme(plot.margin = unit(c(3,.5,3,.5), "cm"))

bus-stop map

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33113267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档