0

I am trying to plot distribution points of a species over a map using R and ggmaps. I followed slightly modified instructions of an other stackoverflow question: R geom_point and ggmap However, it does not work.

My example data is saved in a cvs-file and I call it Coords.

Subspecies   lon        lat
Caryo        46.06667   7.600000
Macro        56.50000   84.966667
Caryo        46.91833   13.873611

My script is as followed:

distmap <- get_map(location = 'eurasia', zoom = 3, source = 'google', maptype = "terrain")
ggmap(distmap)
Coods <- read.csv2("Coords.csv")
Dist <- ggmap(distmap) + geom_point(data=Coords, aes(x=lon, y=lat),color = "red", size = 4)

I know have three problems:

  1. The cutting of the map is too small, however, if I use a zoom of 2, it does not plot the map, but only a gray background with lat and lon on the sides.

  2. At the end of my sript, it does not plot any points on my map.

  3. I want to have the points in different colours, depending on subspecies.

Any ideas?

Alice
  • 35
  • 5
  • 1
    run `Dist` to see the map with points. use `colour = Subspecies` in the `aes` to get colours – Richard Telford Aug 01 '17 at 16:36
  • 1
    If you want the map to show more of the Earth, you will need to use different map source. Selection within ggmap or just `map_data` – Richard Telford Aug 01 '17 at 16:38
  • How may I change selection within ggmap? I also tried to use 'world' instead of 'eurasia', however, it does also not work with a zoom smaller than 3 and thus does not fot for my purpose. – Alice Aug 01 '17 at 16:59
  • I tried: `Dist <- ggmap(distmap) + geom_point(data=Coords, aes(x=lon, y=lat),color = Subspecies, size = 4)` Does not work for the colours, with `"Subspecies"` as well. – Alice Aug 01 '17 at 17:02
  • Yes, `zoom = 3` is smallest available - see `?get_map`. `aes(x=lon, y=lat, color = Subspecies)` – Richard Telford Aug 01 '17 at 17:14
  • Okay. Thank you. Besides the zoom factor, everything is fine. May you tell me how to solve my problem with the map, without changing the rest of my code? Or is this not possible? – Alice Aug 01 '17 at 17:16
  • Try `mp <- map_data(map = "world"); ggplot(Coords, aes(x = lon, y = lat)) + geom_map(map = mp, data = mp, aes(map_id = region), fill = "grey80") + geom_point()` for a very simple map – Richard Telford Aug 01 '17 at 17:18
  • R says: `Error in FUN(X[[i]], ...) : object 'lon' not found` and this refers to the first lon. But I told him where to find `'lon'` immediately at the beginning with `Coords`... – Alice Aug 01 '17 at 17:30
  • put `inherit.aes = FALSE` in geom_map – Richard Telford Aug 01 '17 at 18:06
  • I have a map now, but it is horroably distorted. Compressed at the sides, and long drawn-out towards up and down. – Alice Aug 01 '17 at 18:13
  • `+coord_quickmap` or `?coord_map` – Richard Telford Aug 01 '17 at 18:14

0 Answers0