I want to create a countour map from x, y and z and crop the data with a shapefile using ggplot

I have a dataset with Eastings, Northings and Age. I want to build an age for my data set. The data set is loaded in the following situation: https://www.dropbox.com/s/zmtxluhwuupb9iv/age%20at%202100.csv

The code I used to create a simple graph and outline is as follows:

age2100 <- read.csv("age at 2100.csv",header=TRUE, sep=",") p <- ggplot(age2100, aes(x=Eastings, y=Northings, colour=("Age")))+geom_point() p+geom_density2d() 

The output I got is as follows:

I could not upload the image, so please find the image in the following location:

https://www.dropbox.com/s/5k5gefqi7wz6v36/age.png

Now I want to add a shapefile in the background and copy the outline lines to the shapefile.

The required output is as follows:

https://www.dropbox.com/s/tqhx2t8cqqozwbt/7Q10%20flow%20dye%20from%20P%20and%20S.JPG

How to go from figure 1 to the desired result? If anyone could give me suggestions, that would be great.

Thank you very much.

Jdbaba

+6
source share
1 answer

Two possibilities:

  • If Google Maps is fine, use ggmap .
  • If this should be your shapefile, look at fortify in ggplot , which has methods for SpatialPolygonsDataFrame s.
+2
source

All Articles