1

I'm completely new with plotting geographical data in R but I think I've come quite far already.

What I have is a data frame in R that has coordinates like this (see latitude and longitude print of subConcSumID at the end) and a hypothetical value that I want to plot as "temperature" contour plot. Values of latitude and longitude are from GPS looking like: 44.7338 by 12.61517

I've imported a shapefile that I created with QGIS (latest version) from a coastline map of Europe, of which I successfully clipped a much smaller region. The CRS of the shapefile is set to EPSG: 4326, WGS 84 If I import this into R with readShapePoly function, I am able to plot the shapefile. It looks like this: enter image description here

As you can see, the coordinates are looking like 2400000 by 4650000

As a result R can not combine the shape plot and the geompoint plot as the coordinates do not overlap.

Any suggestions how to get the coordinates of the shapefile converted to the same system as my GPS coordinates in my data frame?

I was copying the code found here: How to clip a shapefile to an interpolated surface (contours) in R?

It all works combined with the answer giving there, except for the coordinate format issue

df$Latitude
44.93461 44.93444 44.93439 44.93343 44.93306 44.93160 44.93112 44.93392    44.93410 44.92855 44.93066 44.93146 44.93044 44.93192 44.93107 44.92988
44.93042 44.93033 44.92962 44.92703 44.92606 44.92434 44.92587 44.92727  44.90031 44.89065 44.73886 44.73962 44.73715 44.73664 44.73617 44.73544
44.73510 44.73677 44.73654 44.73722 44.74338 44.76730 44.77837 44.77568  44.77460 44.76983 44.76714 44.76444 44.75158 44.74025 44.73822 44.73979
44.73725 44.73839 44.73885 44.73471 44.73119 44.73150 44.73135 44.73221  44.73329 44.73579 44.73665 44.73333 44.72992 44.71040 44.66978 44.64047
44.61106 44.58175 44.55234 44.52230 44.49216 44.46211 44.43252 44.40293  44.37327 44.34381 44.31459 44.28541 44.25655 44.22788 44.19921 44.17162
44.14722

df$Longitude
12.61517 12.61588 12.61609 12.70083 12.70032 12.69832 12.69767 12.75989  12.75921 12.76117 12.79462 12.82265 12.82374 12.82424 12.82414 12.82387
12.84457 12.88025 12.88547 12.88555 12.88558 12.88563 12.91230 12.94371  12.88679 12.85946 12.45061 12.44542 12.44771 12.44493 12.44231 12.43971
12.43683 12.44468 12.44698 12.44857 12.45177 12.45009 12.44917 12.44919 12.44919 12.44923 12.44924 12.44926 12.44934 12.44942 12.44881 12.44186
12.45015 12.45394 12.45040 12.47730 12.50563 12.50428 12.50428 12.53437 12.56735 12.60163 12.63081 12.62973 12.62862 12.62648 12.62292 12.62134
12.61974 12.61816 12.61657 12.61541 12.61426 12.61312 12.61185 12.61058 12.60957 12.60842 12.60518 12.60230 12.59826 12.59321 12.58850 12.58288
12.57463

Dummy data to plot:

df$Counts
1472, 1984, 1794, 2614, 2768,  708, 226, 382, 352, 2196, 2324, 2882, 3026, 1864, 754, 3414, 3260, 3254, 2982, 1546, 708, 2902, 3000, 2798, 2400, 2764, 1968, 1498, 436, 1268, 1766, 1884, 1830, 2008, 1390,  942,  950,  984, 1000, 762, 952, 984, 1668, 1270, 1018, 692, 1472,  872, 1232, 1230,  848, 758, 780, 694, 1228, 1130, 938, 1362, 2658, 2306, 2724, 2602, 2538, 1978, 2126, 1678, 1578, 1454, 1498, 1320, 1434, 1134, 1048, 1022, 1056, 914, 562, 706, 1022, 1102, 560
1
  • 1
    Take a look at ?spTransform and I would use rgdal::readOGR to read your shapefile as it retains the projection information and is considerably more flexible. Oct 10, 2016 at 17:39

1 Answer 1

1

The coordinates of the coastline are not in EPSG:4326 WGS84. They would be in the range of 44 North and 12 East as well.

Instead, it might be EPSG:3035 ETRS89 LAEA Europe.

You can use GDAL to override the wrong CRS with

ogr2ogr -a_srs EPSG:3035 -t_srs EPSG:4326 dst_datasource_name src_datasource_name`

Or do the same with RGDAL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.