标签: ggmap

如何在knitr中使用ggmap库的get_map函数?

我的所有R代码都在独立脚本中按预期运行.一旦进入R Markdown文件,get_map()调用就会崩溃.

map <- get_map(location = 'minneapolis', zoom = 9)
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

label:unnamed-chunk-2
sink()中的警告:没有要删除
标签的接收器:unnamed-chunk-2
process_file(文本)中的错误:
从第53-64行退出:close.connection(con)中的错误:无效的连接
调用:knit - > process_file
执行暂停的knitr以状态1终止

任何想法为什么knitr和get_map都不好玩?

r knitr ggmap

3
推荐指数
1
解决办法
1889
查看次数

在R中的谷歌地图上绘制多个点的坐标

我想在点ID的情况下在Google地图上绘制坐标:

数据样本:

          coordinates      id      
1   (7.1735, 45.8688)       2    
2  (7.17254, 45.8689)       3     
3  (7.17164, 45.8692)       4    
4  (7.18018, 45.8716)       5    
5  (7.17807, 45.8701)       6     
6  (7.17723, 45.8692)       7    
7  (7.17524, 45.8681)       8     
8  (7.18141, 45.8718)       9     
9   (7.1793, 45.8702)      10     
10 (7.17836, 45.8707)      11     
11 (7.17519, 45.8697)      12     
12 (7.17938, 45.8708)      13     
13 (7.17551, 45.8693)      14    
14 (7.17684, 45.8694)      15     
15 (7.18099, 45.8726)      17     
16 (7.18015, 45.8725)      18     
17 (7.18122, 45.8736)      19     
18 (7.17491, 45.8692)      20     
19 (7.15497, 45.8706)      25 …
Run Code Online (Sandbox Code Playgroud)

plot google-maps r ggplot2 ggmap

3
推荐指数
1
解决办法
6234
查看次数

R geom_point和ggmap

我想在澳大利亚的R中绘制一个ggmap,并在其数据点上放置一层标记,这些标记对应于以下数据指定的大小:

sitename   lat    lon    sitenum
Sydney     -34    151    1
Melbourne  -37    144    4
Adelaide   -34    138    7
Run Code Online (Sandbox Code Playgroud)

这是我的代码,但是不起作用...

library(ggmap)
map <- get_map(location = 'Australia', zoom = 4)
mapPoints <- ggmap(map) + geom_point(aes(x = lon, y = lat, size = sitenum), alpha = .5)
Run Code Online (Sandbox Code Playgroud)

r ggmap

3
推荐指数
1
解决办法
6820
查看次数

如何绘制具有两个不同管理边界的ggmap?

我想知道如何使用get_mapggmap任何联邦国家(即有省和县的国家)绘制地图.任何国家,除美国外都会很棒.为了使它看起来不错,填充geom_polygon县(任何填充),省份是空的多边形,只有它的轮廓.所以,基本上,它是两个重叠的ggmaps.

你可以在这里获得shapefile:

https://www.dropbox.com/s/4nl685t860x1e8r/municipios_br.zip

rm(list = ls())
library(ggplot2)
library(rgdal)
library(ggmap)

# READ SHAPEFILE OF BOUNDARIES
Map <- readShapePoly("municipios_br.shp")

head(as.data.frame(Map))
Map = gBuffer(Map, width=0, byid=TRUE)
MapC <- fortify(Map, region="CODIGO_MUN") # municipalities
MapP <- fortify(Map, region="CODIGO_UF") # state boundaries
MapC$test <- 1
MapP$test <- 1
MapC <- Map[order(MapC$order),]
MapP <- MapP[order(MapP$order),]
Run Code Online (Sandbox Code Playgroud)

以下代码生成县边界:

google.map <- get_map(location = 'Brazil', zoom=4,maptype="terrain")
m0 <- ggmap(google.map)
m1 <- m0 + geom_polygon(color = 'grey90', size = .01, aes(x=long, y=lat, group=group, fill=as.factor(test)), data=MapC, alpha=.6) …
Run Code Online (Sandbox Code Playgroud)

r ggmap

3
推荐指数
1
解决办法
2656
查看次数

在绘制等高线图时出现错误(如果(if(any(h &lt;= 0))stop(“带宽必须严格为正”),则出错)在R中

对于以下数据

       > head(df)

      Date Longitude Latitude Elevation Max.Temperature Min.Temperature Precipitation     Wind Relative.Humidity    Solar  RO
     1 2014-07-01   77.1875  7.96184     -9999          27.725          26.673  16.115560560 8.395378         0.8132272 23.08192 Yes
     2 2014-07-02   77.1875  7.96184     -9999          27.931          26.897   0.700378560 8.062267         0.8074675 21.48473 Yes
     3 2014-07-03   77.1875  7.96184     -9999          28.179          26.686   0.000000000 9.465022         0.8107901 24.14900  No
     4 2014-07-04   77.1875  7.96184     -9999          27.657          26.545   0.003433226 9.397203         0.8195020 23.42036 Yes
     5 2014-07-05   77.1875  7.96184     -9999          27.157          26.490   1.541518560 8.903047         0.8385059 23.90545 Yes
     6 2014-07-06   77.1875  7.96184     -9999          27.308 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggmap

3
推荐指数
1
解决办法
3815
查看次数

县里的颜色在地图上

我有一个我希望在地图上着色的县列表,但我发现这样做的唯一方法是使用lat/long.这并不像我想要确保所有县都有代表而不仅仅是一个点.

是否有可能在县边界上色?

例:

dput:

    db_loc <- structure(list(X = 1:10, fips = c(5001L, 5001L, 5001L, 5001L, 
5001L, 5001L, 5001L, 5001L, 5001L, 5001L), zip = c(72003L, 72026L, 
72038L, 72042L, 72048L, 72055L, 72073L, 72140L, 72160L, 72166L
), city = c("Almyra", "Casscoe", "Crocketts Bluff", "De Witt", 
"Ethel", "Gillett", "Humphrey", "Saint Charles", "Stuttgart", 
"Tichnor"), latitude = c(34.403216, 34.505369, 34.438327, 34.283347, 
34.28965, 34.109348, 34.396301, 34.383661, 34.479852, 34.061917
), longitude = c(-91.40953, -91.30213, -91.26907, -91.32515, 
-91.13632, -91.36875, -91.66201, -91.15428, -91.53854, -91.24828
)), .Names = c("X", "fips", "zip", …
Run Code Online (Sandbox Code Playgroud)

r ggmap

3
推荐指数
1
解决办法
2277
查看次数

ggmap:'错误:ggplot2不知道如何处理类SpatialPointsDataFrame的数据'

我想用ggmap创建一个地图.我想显示一些点的位置,从具有UTM坐标的数据帧开始.但是,我总是最终得到错误消息:'错误:ggplot2不知道如何处理类SpatialPointsDataFrame的数据'.帮助非常大... o_0

这是我的例子:

#packages
library(rgeos)
library(maptools) 
library(rgdal)    
library(sp)       
library(ggmap) 

#create data frame with UTM coordinates
Point_ID <- c(1,2)
Easting <- c(519769,518250)
Northing <- c(5767155,5766640)

df <- data.frame(Point_ID, Easting, Northing)

#set spatial coordinates to create a Spatial object
myvars <- c("Easting","Northing")
coords <- df[myvars]
sp = SpatialPoints(coords)

spdf = SpatialPointsDataFrame(sp, df)

#define the projection (UTM coordinates zone 30)
proj4string(spdf)=CRS("++proj=utm +zone=30") 

#transformed to geographic coordinates (latitude/longitude)
spdf<- spTransform(spdf, CRS("+proj=longlat +datum=WGS84"))


#create map
myLocation <- "Hereford" 
myMap <- get_map(location = myLocation, zoom=16, maptype= …
Run Code Online (Sandbox Code Playgroud)

r ggmap

3
推荐指数
1
解决办法
5277
查看次数

如何将Google卫星视图用作R中的传单中的图块

许多问题看起来与我的相似,但我无法找到适合的答案.

到目前为止,我使用了令人敬畏的R传单(和ggmap)包:

library(ggmap)
library(leaflet)

coord <-geocode('New York')

map.city <- leaflet() %>%
  addTiles('http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png?apikey=68c4cd328d3b484091812a76fae093fd') %>%
setView(coord$lon, coord$lat, zoom = 11) 
Run Code Online (Sandbox Code Playgroud)

但是,如果我想将谷歌卫星作为地图呢?

我仔细阅读了这篇文章

/sf/ask/657593331/# =

但不明白如何使用那里定义的googleSat函数.

google-maps r satellite-image leaflet ggmap

3
推荐指数
2
解决办法
3320
查看次数

合并单独的大小并在ggplot中填充图例

我正在地图上绘制点数据,并想缩放点大小并填充到另一列。但是,ggplot为大小和填充生成两个单独的图例,我只想要一个。我已经查看了针对同一问题的几种答案,例如,这个答案,但是无法理解我在做什么错。我的理解是,如果两种美学都映射到同一数据,那么应该只有一个图例,对吗?

这是一些代码来说明问题。任何帮助深表感谢!

lat <- rnorm(10,54,12)
long <- rnorm(10,44,12)
val <- rnorm(10,10,3)

df <- as.data.frame(cbind(long,lat,val))

library(ggplot2)
library(scales)
ggplot() +
 geom_point(data=df,
            aes(x=lat,y=long,size=val,fill=val),
            shape=21, alpha=0.6) +
  scale_size_continuous(range = c(2, 12), breaks=pretty_breaks(4)) +
   scale_fill_distiller(direction = -1, palette="RdYlBu") +
    theme_minimal()
Run Code Online (Sandbox Code Playgroud)

gis r ggplot2 ggmap

3
推荐指数
1
解决办法
546
查看次数

使用ggmap和gganimate创建"天桥"地图动画

我有一个人到达某个地点的数据集,他们待了多久,以及他们的家乡位置.我想创建一个动画图表,将它们"飞"到目的地,并在旅行结束后将它们返回原点.但我不确定这是否可行gganimate.目前我似乎只能做一个"开始"和"结束"框架,虽然有点难以判断它是否没有足够的框架来执行预期的操作.

这就像我到目前为止的情况:

library(dplyr)
library(ggplot2)
library(ggmap)
library(gganimate)

#Coordinates
europecoords <- c(left = -23, bottom = 36, right = 27.87, top = 70.7)
londonareacoords <- c(left = -.7, bottom = 51, right = 0.2, top = 52)
londonpointcoords <- as.data.frame(list(lon = -.14, lat = 51.49))

#Get the map we'll use as the background
europe <- get_stamenmap(europecoords, zoom = 4, maptype = "toner-lite")

#Sample dataset configuration
numberofpoints <- 10
balance <- 0.1

#Set up an example dataset
ids <- seq(1:numberofpoints)
arrivalday …
Run Code Online (Sandbox Code Playgroud)

r ggmap gganimate

3
推荐指数
1
解决办法
1092
查看次数

标签 统计

ggmap ×10

r ×10

ggplot2 ×3

google-maps ×2

gganimate ×1

gis ×1

knitr ×1

leaflet ×1

plot ×1

satellite-image ×1