我正在尝试使用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
如何绘制这些点并删除此错误?
答案 0 :(得分: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)