我使用ggsave函数保存了一个图像,如下所示

但我希望有这样的输出

al1 <- get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11, maptype = 'terrain')
lon<--86.304474
lat<-32.362563
df<-data.frame(lon,lat)
a+ggplot(df)
ggmap(al1)+geom_point(data=df,aes(x=lon,y=lat),size=2)
Run Code Online (Sandbox Code Playgroud)
我试图删除x和y轴值但问题是图像在面板上有白色背景但我只想要绘图图像.
我试图绘制一些信息,显示完整的人口,然后在地图上按位置绘制该人口的子集.我已经看到使用同心圆或三维倒锥形的数据可视化来表达这一点.我只是无法弄清楚如何在ggplot/中ggmap
这是一个免费的手版本Paint,显示了我正在做的事情的粗略概念:

这是一个例子的粗略数据:
> dput(df1)
structure(list(zip = c("00210", "00653", "00952", "02571", "04211",
"05286", "06478", "07839", "10090", "11559"), city = c("Portsmouth",
"Guanica", "Sabana Seca", "Wareham", "Auburn", "Craftsbury",
"Oxford", "Greendell", "New York", "Lawrence"), state = c("NH",
"PR", "PR", "MA", "ME", "VT", "CT", "NJ", "NY", "NY"), latitude = c(43.005895,
17.992112, 18.429218, 41.751554, 44.197009, 44.627698, 41.428163,
41.12831, 40.780751, 40.61579), longitude = c(-71.013202, -66.90097,
-66.18014, -70.71059, -70.239485, -72.434398, -73.12729, -74.678956,
-73.977182, -73.73126), timezone = c(-5L, -4L, -4L, -5L, -5L,
-5L, …Run Code Online (Sandbox Code Playgroud) 我想在ggmap上绘制热图.
library(ggmap)
turku<-get_map('turku', zoom=13)
turkumap<-ggmap(turku, extent="device", legend="topleft")
turkumap
turkumap+geom_density2d(mapping=aes(x = lon, y = lat),data = test, )
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Error in (function (x, y, h, n = 25, lims = c(range(x), range(y))) :
bandwidths must be strictly positive
Run Code Online (Sandbox Code Playgroud)
测试变量是:
test
lon lat var1.pred
1 22.25320 60.4314 -67.04862
2 22.25332 60.4314 -67.07793
3 22.25344 60.4314 -67.11007
4 22.25356 60.4314 -67.14517
5 22.25368 60.4314 -67.18336
6 22.25379 60.4314 -67.22478
7 22.25391 60.4314 -67.26956
8 22.25403 60.4314 -67.31783
9 22.25415 60.4314 -67.36973
10 22.25427 …Run Code Online (Sandbox Code Playgroud) 我试图使用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) 我想在谷歌的灰色地图上绘制各个城市的数据点.由于这些城市相距一段距离,我想我会用一个多面的情节.
创建地图很容易; 请参阅下面的图像和代码.但是,每个方面都显示相同的区域 - 在本例中为大伦敦 - 结果是其他城市的点数未显示.
理想情况下,我希望每个方面都显示每个城市的相关点重叠.因此,"卡迪夫"这个方面会显示卡迪夫及其数据点的缩放地图,"伯明翰"会显示伯明翰及其点数等等.我试着改变各种参数,如zoom和center,但我都没有成功.
如何在每个方面展示不同的城市和相关要点?

require(ggmap)
require(reshape)
# create fake data
sites <- data.frame(site = 1:6,
name = c(
"Royal Albert Hall",
"Tower of London",
"Wales Millenium Centre",
"Cardiff Bay Barrage",
"Birmingham Bullring",
"Birmingham New Street Station"
),
coords = c(
"51.501076,-0.177265",
"51.508075,-0.07605",
"51.465211,-3.163208",
"51.44609,-3.166652",
"52.477644,-1.894158",
"52.477487,-1.898836"),
subzone = rep(c('London','Cardiff','Birmingham'), each = 2)
)
# use function from reshape to split/add column
sites = transform(sites,
new = colsplit(coords, split = ",", names …Run Code Online (Sandbox Code Playgroud) 我正在尝试用一些学校创建一个简单的ggmap.我可以轻松地将学校显示为地图上的点(下面的代码).但是,我想带一个学校图标的图像来代替点.
据我所知,annotation_custom不起作用,因为它需要笛卡尔坐标.插图应该有用,但这会为一所学校带来形象,而不是全部.再次尝试将点角色更改为图像,而不仅仅是添加图像.
我怀疑答案在于grImport,subplot以及可能与geom_point对话的功能.但是,我不知所措.
这是一种图像类型,可以作为一个图标:维基媒体毕业帽
这个问题的答案ggplot2中的刻度标记图像可以很好地添加图像,但是,我想将图像用作点字符,并能够根据属性更改颜色,大小等.
# Load needed packages
# install.packages(c("rgdal", "rgeos", "maptools", "ggmap", "sp", "plyr", "XML", "grImport"))
library(rgdal)
library(rgeos)
library(maptools)
library(ggmap)
library(sp)
library(plyr)
library(XML)
library(grImport)
# Define a value for the Seattle Public Schools (SPS) url:
SPSurl <- "http://www.seattleschools.org/modules/cms/pages.phtml? pageid=197023&sessionid=95b8499fc128fde5d7e1335751c73fee&t"
# All of the addresses for SPS, multiple tables:
SPSaddresses <- readHTMLTable(SPSurl)
# Just elementary schools
SPSelementary <- readHTMLTable(SPSurl, which=3, header=T)
# Just keep the names of the schools and addresses
SPSelementary <- SPSelementary[,c(1,3)] …Run Code Online (Sandbox Code Playgroud) 目标是建立像http://rentheatmap.com/sanfrancisco.html这样的东西
我用ggmap得到了地图,并能够在它上面绘制点.
library('ggmap')
map <- get_map(location=c(lon=20.46667, lat=44.81667), zoom=12, maptype='roadmap', color='bw')
positions <- data.frame(lon=rnorm(100, mean=20.46667, sd=0.05), lat=rnorm(100, mean=44.81667, sd=0.05), price=rnorm(10, mean=1000, sd=300))
ggmap(map) + geom_point(data=positions, mapping=aes(lon, lat)) + stat_density2d(data=positions, mapping=aes(x=lon, y=lat, fill=..level..), geom="polygon", alpha=0.3)
Run Code Online (Sandbox Code Playgroud)

这是一个基于密度的漂亮图像.有没有人知道如何制作看起来相同的东西,但是使用position $ property来构建轮廓和比例?
我通过stackoverflow.com彻底查看并没有找到解决方案.
编辑1
positions$price_cuts <- cut(positions$price, breaks=5)
ggmap(map) + stat_density2d(data=positions, mapping=aes(x=lon, y=lat, fill=price_cuts), alpha=0.3, geom="polygon")
Run Code Online (Sandbox Code Playgroud)
五个独立的stat_density图中的结果:

编辑2(来自hrbrmstr)
positions <- data.frame(lon=rnorm(10000, mean=20.46667, sd=0.05), lat=rnorm(10000, mean=44.81667, sd=0.05), price=rnorm(10, mean=1000, sd=300))
positions$price <- ((20.46667 - positions$lon) ^ 2 + (44.81667 - positions$lat) ^ 2) …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制一张美国地图,其中每个州都被它所拥有的数量遮蔽.我已经让阴影工作得很好.然而,我遇到的问题是多边形看起来非常锯齿状(我假设当我尝试将map_data('state')与我的每个状态计数数据框合并时发生了一些事情).合并之前的数据框有49行(Nevada在我的集合中缺少数据),并且在合并之后有更多行(预期用于状态的long/lat项目)但是数据似乎是为每个纬度/长度正确复制的对,所以我不确定为什么poly是如此锯齿状.
码:
ggplot() +
geom_polygon(data=try1, aes(x=long, y=lat, group = group, fill= COUNT)) +
scale_fill_continuous(low='thistle2', high='darkred', guide='colorbar') +
theme_bw() + labs(fill="State Map Try Title1", title='Title2', x='', y='') +
scale_y_continuous(breaks=c()) +
scale_x_continuous(breaks=c()) +
theme(panel.border = element_blank())
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激(显然,如果有更好的方法,我会接受建议!).

观察到的行为:从上图可以看出,各国的名称与其实际几何形状不匹配.
预期的行为:我想将数据框与其几何图形正确连接,并在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) 我通常用来ggmap在简单的城市地图上绘制点.今天这样做时,我遇到了一个新的错误,禁止我使用该功能get_map()
#get API key @ https://developers.google.com/places/web-service/get-api-key
key<-"AIzaSyCYgKKt2fn7Crt-V6Hnc5aw5lSfy7XLQ-Y"
register_google(key = key)
atw<- get_map(location=c(-88.68,42.14), zoom=10, scale=2)
Run Code Online (Sandbox Code Playgroud)
我不确定问题出在哪里.我尝试了一个新的API密钥,但没有运气.有什么输入?
错误如下:
无法打开网址' https://maps.googleapis.com/maps/api/staticmap?center=42.14,-88.68&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=AIzaSyCYgKKt2fn7Crt-V6Hnc5aw5lSfy7XLQ-Y':HTTP状态为download.file中的'403 Forbidden'错误(url,destfile = destfile,quiet =!messaging,mode ="wb"):无法打开网址' https://maps.googleapis.com/maps/api/staticmap?center= 42.14,-88.68&zoom = 10&size = 640x640&scale = 2&maptype = terrain&language = en-EN&key = AIzaSyCYgKKt2fn7Crt-V6Hnc5aw5lSfy7XLQ-Y '