【问题标题】:Error in adding points to ggmake plot向ggmake图添加点时出错
【发布时间】:2018-04-05 20:21:37
【问题描述】:

我正在尝试使用 ggmake 创建一个绘图,该绘图已创建,但随后我想使用 geom_point 添加点,为此我给出了城市的经度和纬度,但由于错误未能实现,下面我有粘贴了包含经度和纬度的代码和数据框。

City    Longitude   Latitude
Mastung 66.84691    29.4087
Khuzdaar    66.611691   27.812
Khaich  63.01475    26.156
Panjgore    64.112336   26.97524
Quetta  66.998734   30.1829713
Dera Bugti  69.159609   29.035158 
Kohlo   69.24901    29.8975
Kalat   66.5878 29.0303
Kharaan 65.4222 28.5812
Nooshki 66.0195 29.555

kl <- read.csv(file.choose())
map <- get_map(location=c(66.214995,28.538837), zoom=7) + geom_point(data =     
kl,aes(x =longitude,y = latitude,size =4),color='red')
Error:Error in Ops.raster(get_map(location = c(66.214995, 28.538837), zoom = 7),  
: operator not meaningful for raster objects

如何绘制这些点并消除此错误?

【问题讨论】:

    标签: r maps ggmap


    【解决方案1】:
    kl <- read.table(text='
    City    longitude   latitude
    "Mastung" 66.84691    29.4087
    "Khuzdaar"    66.611691   27.812
    "Khaich"  63.01475    26.156
    "Panjgore"    64.112336   26.97524
    "Quetta"  66.998734   30.1829713
    "Dera Bugti"  69.159609   29.035158 
    "Kohlo"   69.24901    29.8975
    "Kalat"   66.5878 29.0303
    "Kharaan" 65.4222 28.5812
    "Nooshki" 66.0195 29.555
    ', header=T)
    
    library(ggmap)
    
    mp <- get_map(location=c(66.214995,28.538837), zoom=7) 
    ggmap(mp) +
    geom_point(data=kl, aes(x=longitude, y=latitude), color='red', size=4)
    

    【讨论】:

    • 感谢您的回答,但图表未显示右侧两个区域的名称,如何将城市列中的名称与地图上的点一起打印?因为如果我增加缩放,那么某些区域会超出图像?
    • @AmmarSabirCheema 这是地图的问题,而不是代码的问题。我很抱歉。请考虑投票并接受我的回答,谢谢。
    猜你喜欢
    • 2017-05-24
    • 2011-05-11
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多