Jd Baba
Jd Baba

Reputation: 6118

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

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

The code I used to create the simple graph and contour 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 couldn't upload the image so please find the image at the following dropbox location :

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

Now, I want to add a shapefile on the background and clip the contour lines to the shapefile.

The desired output is as follows:

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

How do I proceed from figure 1 to desired output ? If anyone could give me suggestions, that would be great.

Thank you so much.

Jdbaba

Upvotes: 6

Views: 305

Answers (1)

Ari B. Friedman
Ari B. Friedman

Reputation: 72769

Two possibilities:

  1. If Google Maps is ok, then use ggmap.
  2. If it has to be your shapefile, look at fortify in ggplot, which has methods for SpatialPolygonsDataFrames.

Upvotes: 2

Related Questions