I have two maps generated by two different methods. The first, I used maps package and the function map() and symbols(). On the other hand, I used the ggmap package with the ggmap() and geom_point() functions. This the structure of my data and my code:
> str(city_frequency)
'data.frame': 144 obs. of 4 variables:
$ city: Factor w/ 144 levels "A Coruna","Agen",..: 1 2 3 4 5 6 7 8 9 10 ...
$ freq: int 7 2 4 1 4 2 1 1 1 5 ...
$ lon : num -8.412 0.616 -8.446 -4.262 2.149 ...
$ lat : num 43.4 44.2 40.6 42.8 43.9 ...
xlim <- c(-13.08, 8.68)
ylim <- c(34.87, 49.50)
map("world", lwd=0.05, xlim=xlim, ylim=ylim)
symbols(city_frequency$lon, city_frequency$lat, circles=sqrt(city_frequency$freq), bg="#93ceef", fg="#ffffff", lwd=0.5, inches=0.15, add=TRUE)
m <- get_map("France", zoom = 5, maptype = "toner")
ggmap(m) + geom_point(data = city_frequency, aes(lon = lon, lat = lat, size = sqrt(freq)), alpha = 0.7) + labs(x = "longitude", y = "latitude", title = "City Frequency")
The thing is that in the second map all the points are located a little bit North from the right place. How can I solve this problem? Thanks in advance.
Note: in order to get the coordinates of my data frame I used the geocode() in a early step.
---> I have created a public repository in github in order that everyone can access my data frames. Feel free to play with them.
Aucun commentaire:
Enregistrer un commentaire