我正在使用埃博拉数据集,在数据集中没有给出位置坐标。我想手动将经度和纬度分配给该位置,这样我就可以将位置绘制到谷歌地图上。我想在R.任何想法,我一直在尝试这个,但对我不起作用:
if(ebola$Country == 'Guinea' & ebola$Location == 'Conakry')
{
conakry <- c(9.5092,13.7122)
}
我正在使用埃博拉数据集,在数据集中没有给出位置坐标。我想手动将经度和纬度分配给该位置,这样我就可以将位置绘制到谷歌地图上。我想在R.任何想法,我一直在尝试这个,但对我不起作用:
if(ebola$Country == 'Guinea' & ebola$Location == 'Conakry')
{
conakry <- c(9.5092,13.7122)
}
#Dataset example
df <- read.table(text = "Col1 Col2 Location
1 2 Conkary
3 1 Monrovia
2 2 Freetown
1 3 Greenville",
header = TRUE, stringsAsFactors = FALSE)
#Create a Dataframe with geographic information
Geo <- read.table(text = "Country Location LON LAT
Guinea Conkary 9.5092 -13.7122
Liberia Monrovia 6.3000 -10.7659
",
header = TRUE, stringsAsFactors = FALSE)
library(plyr)
df_Geo <- join(df, Geo, by = "Location", type= "left")
df_Geo2 <- join(df, Geo, by = "Location", type="right")
#Create a SpatialPoints Object
library(sp)
Coords <- cbind(as.numeric(df_Geo2$LON),as.numeric(df_Geo2$LAT))
row.names(Coords) <- 1:nrow(Coords)
#Choosing the projection, should be good for google maps
LLCRS <- CRS("+proj=longlat +ellps=WGS84")
Coords_sp <- SpatialPoints(Coords, proj4string = LLCRS)
#Create a SpatialPointsDataFrame
Ebola.sp <- SpatialPointsDataFrame(Coords_sp, df_Geo2, proj4string = LLCRS, match.ID = TRUE)
#Plot on GoogleMaps
library(plotGoogleMaps)
map <- plotGoogleMaps(Ebola.sp, filename='MapEbola.html')
#Coordinates are inexact due to bad projection.