Ammar Sabir Cheema
Ammar Sabir Cheema

Reputation: 990

Error in adding points to ggmake plot

I am trying to create a plot using ggmake, the plot is created but then I want to add points using geom_point, for this I gave longitude and latitudes of the cities but failed in achieving this because of an error,below I have pasted the code and dataframe containing longitudes and latitudes.

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

How to plot these points and remove this error?

Upvotes: 0

Views: 136

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

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)

enter image description here

Upvotes: 1

Related Questions