我是R的新手,我正在玩一个项目来绘制2010年到2020年阿拉巴马州预计的人口增长情况.这是我的代码:
dat <- read.table("C:/Users/rasmus/Documents/countyinfo.txt", sep="\t", header=TRUE)
library(ggplot2)
library(maps)
library(ggmap)
mdat <- map_data('county')
str(mdat)
al1 = get_map(location = c(lon = -86.304474, lat = 32.362563),
zoom = 7, maptype = 'roadmap')
al1MAP = ggmap(al1) +
geom_point(data=dat,inherit.aes = FALSE,
aes(y=Lat, x=Lon, map_id=County, size=Growth), col="red") +
borders("state", colour="red", alpha=0.8) +
borders("county", colour="blue", alpha=0.5)
al1MAP
Run Code Online (Sandbox Code Playgroud)
现在,我有两个问题.
1)国家边界似乎做了奇怪的事情.这是关闭县覆盖的屏幕截图:

2)鉴于这只是关于阿拉巴马州,我想关闭国界以外的边界,但我不知道该怎么做.我的猜测是试验xlim和ylim,但我不知道如何限制它们到阿拉巴马边界多边形.
我非常感谢有关ggmap和stamen水彩问题的一些帮助/想法.
每次我尝试创建一个雄蕊水彩地图时,我都会收到相同的错误消息:
"Error in readPNG(destfile) : file is not in PNG format"
Run Code Online (Sandbox Code Playgroud)
以下是返回此错误的简单代码的一些示例:
qmap("new-york", zoom=13, source="stamen", maptype="watercolor")
Run Code Online (Sandbox Code Playgroud)
要么
get_map(location='Auckland', source="stamen", maptype="watercolor", zoom=13)
Run Code Online (Sandbox Code Playgroud)
我在Windows 8下使用r版本:[默认] [64位] C:\ Program Files\R\R-3.0.2
我意识到有几个人发布了同样的问题 - 但只有少数 - 我没有看到任何解释/建议.我很难过和沮丧,我真的希望有比我更多经验的人遇到(并解决)这个问题.提前致谢或您可以提供任何帮助
我正在尝试将实体在谷歌地图上的运动绘制为一组使用的有向线ggmap.目前我正在使用从中绘制线段的geom_segment调用ggplot2.但是,如果1->2->1线条重叠,则运动中存在周期.这使得从可视化中找出运动变得更加困难.
有没有办法弯曲线段来处理这个?或者我可以尝试其他方法或库吗?
我可以把路易斯安那州的情节很好......
require(ggplot2)
require(ggmap)
require(maps)
LA <- map_data("state", region="louisiana")
ggplot(LA, aes(x=long, y=lat))+geom_polygon()
Run Code Online (Sandbox Code Playgroud)
现在,我有关于洛杉矶特定城市的销售电话数量的数据.如何为每个城市添加一个积分,以便对该地块进行销售电话?
salesCalls <- data.frame(State=rep("louisiana",5),
City=c("Baton Rouge", "New Orleans", "Shreveport", "Lafayette", "Mandeville"),
Calls=c(10,5,8,13,2))
salesCalls
State City Calls
1 louisiana Baton Rouge 10
2 louisiana New Orleans 5
3 louisiana Shreveport 8
4 louisiana Lafayette 13
5 louisiana Mandeville 2
Run Code Online (Sandbox Code Playgroud) 这个等式来自我之前的问题.我想绘制代表总人口的点,到目前为止,我习惯于scale_size使点的大小相对于总人口而言.
但是,我想让这些点透明,因为点覆盖了地图.但是,只要我尝试发送的消息清楚,我就可以使用其他选项.

# load required packages
library(ggmap)
library(ggplot2)
# query map of Birmingham, AL
al1 <- get_map(location = c(lon = -86.304474, lat = 32.362563), zoom = 11,
source = "osm", maptype = 'terrain')
al1MAP <- ggmap(al1)+ geom_point(data=quote_bmh,
aes(x=IntPtLon, y=IntPtLat, size=TotPop, colour="gold2"),
colour="gold2") + scale_size(range=c(0,15))
Run Code Online (Sandbox Code Playgroud) 在下面的脚本中,我读了许多点对并在地图上绘制线条.我正在使用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) 我有一些R代码用ggmap在地图上绘制数据.它上周工作正常.但是,现在当我运行该行来获取地图时:
emap <- get_map(c(-2.503704,43.18735),zoom=9,maptype="roadmap",color="bw")
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
cannot open compressed file '/var/folders/2w/2wSOAL2LFUC+2QkRaR1wI++++TI/-Tmp-//Rtmpj0TMx5/ggmap/index.rds', probable reason 'No such file or directory'
Run Code Online (Sandbox Code Playgroud)
我搜索了这个论坛和网络,但找不到任何其他线程讨论此错误.
任何帮助深表感谢.此致,Noelia
PS:sessionInfo()返回以下内容:
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mapproj_1.2-2 maps_2.3-9 ggmap_2.4 dplyr_0.4.1 xtable_1.7-4 ggplot2_1.0.1 reshape2_1.4.1
loaded via a namespace (and not attached):
[1] assertthat_0.1 colorspace_1.2-6 DBI_0.3.1 …Run Code Online (Sandbox Code Playgroud) 的背景
我有一个问题,其中有许多解决方案可能,但我相信有一个尚未发现的优雅解决方案利用purrr.
示例代码
我有一个如下的大数据框,我在其中包含了一个例子:
library(tibble)
library(ggmap)
library(purrr)
library(dplyr)
# Define Example Data
df <- frame_data(
~Street, ~City, ~State, ~Zip, ~lon, ~lat,
"226 W 46th St", "New York", "New York", 10036, -73.9867, 40.75902,
"5th Ave", "New York", "New York", 10022, NA, NA,
"75 Broadway", "New York", "New York", 10006, -74.01205, 40.70814,
"350 5th Ave", "New York", "New York", 10118, -73.98566, 40.74871,
"20 Sagamore Hill Rd", "Oyster Bay", "New York", 11771, NA, NA,
"45 Rockefeller Plaza", "New York", "New York", 10111, -73.97771, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用GGmap按州创建车辆撞车图。该地图将包含根据该州发生的车祸次数确定大小的点。
特别是,我试图重新创建此博客文章的可视化群集部分中所示的美国图解。。
但是,每当我尝试创建地图时,都会出现此错误。
Error in aperm.default(map, c(2, 1, 3)) :
invalid first argument, must be an array
Run Code Online (Sandbox Code Playgroud)
我已经设置了Google API,并看到它收到了点击数。我也启用了它并拥有密钥。
另外,我使用以下命令从github帐户安装了GGmap:
devtools::install_github("dkahle/ggmap", ref = "tidyup", force=TRUE)
Run Code Online (Sandbox Code Playgroud)
由于CRAN尚未更新。
我也重新启动并退出了R,但错误仍然存在。
即使我只是简单地运行:
get_map()
Run Code Online (Sandbox Code Playgroud)
它仍然导致错误:
Error in aperm.default(map, c(2, 1, 3)) :
invalid first argument, must be an array
Run Code Online (Sandbox Code Playgroud)
以下是我的代码,它类似于博客文章中的代码:
mydata$State <- as.character(mydata$State)
mydata$MV.Number = as.numeric(mydata$MV.Number)
mydata = mydata[mydata$State != "Alaska", ]
mydata = mydata[mydata$State != "Hawaii", ]
devtools::install_github("dkahle/ggmap", ref = "tidyup", force=TRUE)
library(ggmap)
ggmap::register_google(key = "...") #my key is here
for …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ggmap 从谷歌地图调用地图。示例代码:
get_googlemap(center = c(lon = -56.67, lat = 51.47), zoom = 8, size = c(640, 640), scale = 2,
format = "png8", maptype = "satellite")
Run Code Online (Sandbox Code Playgroud)
但是,这会返回以下错误:
来源:https : //maps.googleapis.com/maps/api/staticmap?center= 24.8,-81.7 &zoom=8&size=640x640&scale=4&maptype=satellite& key=(已删除发布键)
Error in aperm.default(map, c(2, 1, 3)) :
invalid first argument, must be an array
In addition: Warning message:
In get_googlemap(center = c(lon = -81.7, lat = 24.8), zoom = 8, :
HTTP 400 Bad Request
Run Code Online (Sandbox Code Playgroud)
我查看了人们遇到类似问题的线程。在对 API 密钥和限制进行一些摆弄之后,它们似乎得到了解决。在这种情况下,我做了以下事情:
ggmap ×10
r ×9
ggplot2 ×5
google-maps ×2
api ×1
dictionary ×1
geocoding ×1
maps ×1
plot ×1
png ×1
purrr ×1
stamen-maps ×1
telemetry ×1