我有两个具有经度和纬度坐标的地图。在第一张地图中,我有一个巴西州及其城市。它是这样构建的:
library("ggplot2")
library("ggrepel")
library("maptools")
library("broom")
library (brazilmaps)
###MAP 1
map_brazil <- readShapeSpatial("Shapefiles/municipios_2010.shp") ### do download and upload the file
###CHANGE TO DATA FRAME
map.tidy <- tidy(map_brazil, region = "id")
map.tidy <- merge(map.tidy, map_brazil@data, by = "id")
map.mg <- map.tidy[map.tidy$uf == "MG", ] ###state of brazil
ggplot(map.mg) +
aes(long, lat, group = group) +
geom_polygon() +
coord_equal()
ggplot(map.mg) +
aes(long, lat, group = group) +
geom_polygon(fill="white", aes(group=group)) +
geom_path(color="grey20") + coord_equal()
###END MAP 1
在第二个中,我具有起点和终点的坐标以及医疗预约的数量(起点城市和进行咨询的城市)。
##MAP 2
LAT_ORIGIN <- c('-16.17892242','-18.73383175','-15.96928917','-17.68925903','-17.1866273','-18.2417823')
LON_ORIGIN <- c('-40.69450345','-43.36417123','-41.49511178','-42.51506114','-41.70070843','-43.60346385')
LAT_DESTINATION <- c('-19.91112942','-19.91112942','-16.16912397','-16.72863755','-18.85492496','-18.75319873')
LON_DESTINATION <- c('-43.92731356','-43.92731356','-42.29595038','-43.85817259','-41.95588455','-44.43063064')
CONSULTATION <- c(10,2,8,15,25,9)
DF <- data.frame(LAT_ORIGIN,LON_ORIGIN,LAT_DESTINATION,LON_DESTINATION,CONSULTATION)
DF$LAT_ORIGIN = as.numeric(as.character(DF$LAT_ORIGIN))
DF$LON_ORIGIN = as.numeric(as.character(DF$LON_ORIGIN))
DF$LAT_DESTINATION = as.numeric(as.character(DF$LAT_DESTINATION))
DF$LON_DESTINATION = as.numeric(as.character(DF$LON_DESTINATION))
xquiet<- scale_x_continuous("", breaks=NULL)
yquiet<-scale_y_continuous("", breaks=NULL)
quiet<-list(xquiet, yquiet)
ggplot(DF, aes(LAT_ORIGIN,LON_ORIGIN))+geom_segment(aes(x=LAT_ORIGIN, y=LON_ORIGIN,xend=LAT_DESTINATION, yend=LON_DESTINATION, alpha=CONSULTATION), col="red")+
scale_alpha_continuous(range = c(0.1, 0.9))
+quiet
###END MAP 2
是否可以通过结合这两个代码来构建单个地图?那么,是否有可能在MAP 1中合并出发地和目的地城市?