标签: ggmap

使用OpenStreetMap从data.frame绘制点

我是一个有空间数据的完整新手.我有以下代码成功绘制有界地图.我想补充一下,data.frame存储点.我提前道歉,因为无法从OpenStreetMap文档中找到这个...下面的代码:

library(OpenStreetMap)
stores <- data.frame(name=c("Commercial","Union","Bedford"),
                 longitude=c(-70.25042295455933,-70.26050806045532,-70.27726650238037),
                 latitude=c(43.657471302616806,43.65663299041943,43.66091757424481))
lat <- c(43.68093,43.64278)
lon <- c(-70.29548,-70.24097)
portland <- openmap(c(lat[1],lon[1]),c(lat[2],lon[2]),zoom=15,'osm')
plot(portland,raster=TRUE)
#can't figure out what to put here.
Run Code Online (Sandbox Code Playgroud)

我怀疑商店的格式不适合空间数据.

r openstreetmap ggmap

7
推荐指数
1
解决办法
7387
查看次数

R ggmap:为什么我可以使用filename属性创建矩形地图,但不能在绘图中使用它们?

我想在R中创建一个世界地图.我有点熟悉ggmap,所以我尝试过这样的事情:

ggmap(get_googlemap(center=c(83,25),
                    zoom=1, scale=4, filename="world", size=c(640,300)))
Run Code Online (Sandbox Code Playgroud)

就这一点而言,它确实工作正常world.png.

world.png输出

我真的很高兴能找到一个解决办法,因为ggmap"无法显示任何高于80°纬度的东西"问题,因此创建整个世界的地图或多或少是不可能的.

然而,在R本身中,即在图中,地图看起来并不像它应该的那样: 失败的R地图

这仅在地图为矩形(当相应地size设置属性时)而非正方形(默认情况下)时发生.

为什么?这个问题将来有可能得到解决吗?从这里到最合适的世界地图最快的方式是什么?

maps google-maps r ggplot2 ggmap

7
推荐指数
1
解决办法
1061
查看次数

使用ggmap创建正交贴图

在下面的脚本中,我读了许多点对并在地图上绘制线条.我正在使用ggmap从谷歌中提取地图来绘制这条线:

source('./library/latlong2state.R')

library(maps)
library(mapproj)
library(mapdata)
library(geosphere)
library(ggmap)

fileName = "_CanadaData/CanadaHospitalComplete.csv"

getLineColor <- function(val) {
  pal <- colorRampPalette(lineColours)
  colors <- pal(80)
  val.log <- log(val)

  if (val > 50) {
    col <- colors[80]
  } else {
    colindex <- max(1, round( 80 * val / 50))
    col <- colors[colindex]
  }
  return(col)
}

# Load the data
location <- read.csv(fileName, stringsAsFactors=FALSE)

# Omit locations that are not on the map of focus (not needed for city maps unless they are on a border)
location$state …
Run Code Online (Sandbox Code Playgroud)

maps google-maps r map-projections ggmap

7
推荐指数
1
解决办法
739
查看次数

ggmap:使用开放街道地图作为源时出错

我是R的新手,我正在关注这篇文章来学习ggmap.

qmap("Forbidden city",zoom=15)
qmap("Forbidden city",zoom=15, source="osm")
Run Code Online (Sandbox Code Playgroud)

虽然上面的第一个命令工作正常,但第二个命令给我一个错误信息:

来自网址的地图:http: //maps.googleapis.com/maps/api/staticmap?centre = Forbidden+city&zoom = 15&size =%20640x640&maptype = terrain&sensor = false Google Maps API服务条款:http://developers.google. com/maps/terms 网址中的信息:http ://maps.googleapis.com/maps/api/geocode/json?address = Forbidden+city&sensor = false Google Maps API服务条款:http://developers.google.com/maps/terms 错误:地图抓取失败 - 请参阅?get_openstreetmap中的详细信息.另外:警告信息:在download.file(url,destfile = destfile,quiet =!messaging,mode ="wb"):无法打开:HTTP状态为'503 Service Unavailable'

任何帮助表示赞赏.

r openstreetmap ggmap

7
推荐指数
1
解决办法
2682
查看次数

使用ggmap绘制形状文件:当shape文件大于ggmap时剪切

当我尝试将ggmap与shape文件组合时,我遇到了剪辑问题.Kahle和Wickham(2013:158)中的示例工作正常,因为ggmap中的栅格图像覆盖整个形状文件.下面是当我尝试在覆盖较小区域的ggmap图上绘制美国州的形状文件时会发生什么的示例.ggmap显示了纽约市,我希望用美国各州的边界覆盖它(仅作为示例).生成的地图没有任何意义.问题是形状文件被剪裁,ggplot连接未剪切的点.下面是代码.形状文件来自这里.我只是在这里展示最后的情节.

我怎么解决这个问题?

path <- "PATH TO SHAPEFILE"
library("ggmap")
library("rgdal")

# shapefile
states <- readOGR(dsn = path, layer = "states")
states_df <- fortify(states)
# plot shapefile
plot(states, lwd = 0.1)
ggplot(states_df, aes(long, lat, group = group)) +
    geom_polygon(colour = "black", fill = NA, size = 0.1)


# combine ggmap with shapefile
map <- get_map("new york city", zoom = 10, source = "stamen")
ggmap(map, extent = "device")

ggmap(map, extent = "device") +
    geom_polygon(aes(long, lat, group=group), data = states_df, colour = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggmap

7
推荐指数
1
解决办法
1986
查看次数

geom_point如何删除包含缺失值的行?

我不确定为什么我的数据点都没有显示在地图上.

   Store_ID visits CRIND_CC  ISCC  EBITDAR top_bottom   Latitude  Longitude
      (int)  (int)    (int) (int)    (dbl)      (chr)     (fctr)     (fctr)
1        92    348    14819 39013 76449.15        top  41.731373  -93.58184
2      2035    289    15584 35961 72454.42        top  41.589428  -93.80785
3        50    266    14117 27262 49775.02        top  41.559017  -93.77287
4       156    266     7797 25095 28645.95        top    41.6143 -93.834404
5        66    234     8314 18718 46325.12        top    41.6002 -93.779236
6       207     18     2159 17999 20097.99     bottom  41.636208 -93.531876
7        59     23    10547 28806 52168.07     bottom   41.56153  -93.88083 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggmap

7
推荐指数
1
解决办法
1万
查看次数

在ggmap中绘制曲线,geom_curve无法正常工作

我想用城市之间的曲线绘制荷兰地图.我有两个名为one的数据帧:df_verticles其中包含24个具有lat/lon组合的城市.第二个数据框称为:df我想用于在lat/lon之间绘制一条曲线,从组合到lat/lon到组合.

> head(df_vertices)
        city AmountSessions   totalkWh AmountRFID scaledAmount   scaledkWh Latitude Longitude
1    Alkmaar          13608  104554.68       1326   0.07139012 0.026941910 52.63903  4.755538
2     Almere          11281  100841.42        930   0.05006999 0.025985067 52.39447  5.282043
3 Amersfoort           7719   67663.30       1198   0.06449876 0.017435647 52.15108  5.383069
4 Amstelveen          25794  236437.93       2616   0.14084204 0.060925915 52.31724  4.859266
5  Amsterdam         402365 3880744.86      18574   1.00000000 1.000000000 52.34560  4.808834

> head(df)
CityChargeSessions   NextCity Amount    sumkWh scaledAmount  scaledkWh Latitude_from Longitude_from Latitude_to Longitude_to
1          Amsterdam    Alkmaar   1058  8133.736   0.18438480 0.15480933      52.34560 …
Run Code Online (Sandbox Code Playgroud)

r coordinates ggplot2 ggmap

7
推荐指数
1
解决办法
2976
查看次数

如何从ggmap中删除边距

我试图使用ggmap包绘制地图,没有任何边距,轴,标签等.我能够删除标签,轴但不知道必须删除边距.任何帮助将不胜感激..!

library("ggmap")
amap <- get_map(location = c(lon = -95.3632715, lat = 29.7632836), maptype = c("terrain"))
basemap <- ggmap(amap)
plot(basemap)
Run Code Online (Sandbox Code Playgroud)

r margin map ggmap

6
推荐指数
2
解决办法
3794
查看次数

如何使用ggmap正确连接数据和几何

一张图片胜过千言万语: 数据与几何不匹配

观察到的行为:从上图可以看出,各国的名称与其实际几何形状不匹配.

预期的行为:我想将数据框与其几何图形正确连接,并在ggmap中显示结果.

我以前加入了不同的数据框架,但事实上显然ggmap需要"强化"(实际上我不知道究竟是什么意思)数据框以显示结果.

这是我到目前为止所做的:

library(rgdal)
library(dplyr)
library(broom)
library(ggmap)

# Load GeoJSON file with countries.
countries = readOGR(dsn = "https://gist.githubusercontent.com/ccamara/fc26d8bb7e777488b446fbaad1e6ea63/raw/a6f69b6c3b4a75b02858e966b9d36c85982cbd32/countries.geojson")

# Load dataframe.
df = read.csv("https://gist.githubusercontent.com/ccamara/fc26d8bb7e777488b446fbaad1e6ea63/raw/a6f69b6c3b4a75b02858e966b9d36c85982cbd32/sample-dataframe.csv")

# Join geometry with dataframe.
countries$iso_a2 = as.factor(countries$iso_a2)
countries@data = left_join(countries@data, df, by = c('iso_a2' = 'country_code'))

# Convert to dataframe so it can be used by ggmap.
countries.t = tidy(countries)

# Here's where the problem starts, as by doing so, data has been lost!

# Recover attributes' table that …
Run Code Online (Sandbox Code Playgroud)

r ggmap

6
推荐指数
1
解决办法
450
查看次数

使用R中usmap包中的plot_usmap在同一张地图上绘制州和县边界

我想创建一张显示州和县边界(即不同颜色的州边界)的美国地图。我通常使用导入的形状文件或使用 的函数来执行此ggplot2操作map_data。然而,我面临三个障碍。

1)我无法在我的计算环境中安装gdalgeos,因此无法使用任何形状文件或 GeoJSON 文件(我尝试加载使用的地图县级形状文件fastshp尚未成功,但我愿意接受任何可以重现地图的解决方案低于但包括州边界)。

map_data2)我需要包括夏威夷和阿拉斯加,这样就排除了from的使用ggplot2

3)我需要地图包括州和县边界,这使得使用usmap包成为问题,因为它是包装函数,ggplot2但没有轻松和一般的能力来定制原始ggplot2对象的级别。

4)此外,无法使用sf包 bc 它具有非 R 库依赖项(units包依赖于 C 库libudunits2)。

我需要什么:一张可以投影阿拉斯加和夏威夷并使用对比色显示州和县边界的地图,我需要完成所有这一切,而无需诉诸任何依赖rgeosrgdal和/或 的软件包units

到目前为止我plot_usmapusmap包中尝试过的内容:

library(dplyr)
library(stringr)
library(ggplot2)
library(usmap)
library(mapproj)
devtools::install_github("wmurphyrd/fiftystater")
library(fiftystater)

county_data<-read.csv("https://www.ers.usda.gov/webdocs/DataFiles/48747/PovertyEstimates.csv?v=2529") %>% #
  filter(Area_name != "United States") %>%
  select(FIPStxt, Stabr, Area_name, PCTPOVALL_2017) %>%
  rename(fips = FIPStxt)
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
state_map …
Run Code Online (Sandbox Code Playgroud)

mapping r ggplot2 ggmap

6
推荐指数
1
解决办法
3263
查看次数