0

I'm trying to plot data on map of switzerland using this code

require("rgdal")
require("maptools")
require("ggplot2")
require("plyr")
require("maps")
require("ggmap")

ggplot() + geom_polygon(data = da, aes(x=long, y = lat)) + 
coord_fixed(1.3)+
geom_point(data=de, aes(x=lat, y=lon), color="orange") 

Where data da is a map using swissmap package:

 da<- shp_df[[6]]

& data de is:

'data.frame':   115 obs. of  5 variables:
 $ FB    : Factor w/ 3 levels "I","II","IV": 2 2 2 3 1 2 1 3 1 1
 $ Nom   : Factor w/ 115 levels "\"Patient Education\" Programm unipolare Depression",..: 9 31 95 112 92 41 70 84 13 21 ...
 $ lon  : num  7.36 8.54 7.08 NA 7.45 ...
 $ lat  : num  46.2 47.4 46.1 NA 46.9 ...
 $ Coûts: int  100000 380000 150000 300000 2544000 300000 1897000 500000 2930000 2400000 ...

I got this result.enter image description here This is not what i want, i'm trying to plot at location (sometime same place)the data in de dataset. Any kinds of help or advices will be appreciate . thank you

r tremeaud
  • 161
  • 1
  • 3
  • 11
  • 1
    You use `aes(x=long, y = lat)` in one place and `aes(x=lat, y=lon)` (reversed) in another. I've done that a few times. (But that's not all of your problem, just something that will bite you when you fix the other part.) – r2evans May 15 '18 at 20:59
  • OK I take note of it thanks – r tremeaud May 15 '18 at 21:11
  • Are you using [`ggswissmaps`](https://cran.r-project.org/web/packages/ggswissmaps/index.html)? If yes, looking at the data, it appears that `lat` and `long` are nowhere near "degrees" (just do `str(shp_df[[6]])` to see). Try `lapply(shp_df[[6]][1:2], range)` and you'll see lat ranges 75286-295933, when I would expect it to be around 46-47 degrees North. So I believe the problem is not with your code, it's with *units*. – r2evans May 15 '18 at 21:39
  • I just don't understand what you are saying ? there is an error in the package, how you suggest to fix this problem ? – r tremeaud May 15 '18 at 21:43
  • 1
    Either (a) don't use that package, or (b) find out what units they are using and translate either the map data or your data. Since it's not on CRAN and has not been updated in a bit, perhaps you could consider using packages `maps` or `ggmap`. Bottom line: I don't know for certain what the units are, and without a clear definition, everything you do will be conjecture and therefore not-validated (e.g., "suspect"). – r2evans May 15 '18 at 21:45

0 Answers0