0

I am new in R and I want to plot a map with the distribution/ contour of pollutants and I have trouble doing that.

I a sample of my dataset is:

> head(noxco2_contour)
  latitude longitude    NOX.CO2
1 52.45060 -1.933200 0.01240829
2 52.45061 -1.933198 0.01045806
3 52.45060 -1.933207 0.01235869
4 52.45059 -1.933202 0.01083601
5 52.45059 -1.933199 0.01243808
6 52.45058 -1.933207 0.01379813

After getting the needed map with ggmap, I'm trying to overplot filled contours of NOX.CO2. and I am using this code:

`ggmap(west_midlands, extent = "panel") + geom_density2d(data = noxco2_contour, aes(x = longitude, y = latitude, z=NOX.CO2), size = 0.3, contour=T) + 
  stat_density2d(data = noxco2_contour, 
                 aes(x = longitude, y = latitude, z= NOX.CO2, fill = ..level.., alpha = ..level..), size = 0.05, 
                geom = "polygon") + scale_fill_gradient(low = "green", high = "red") + 
  scale_alpha(range = c(0, 1), guide = FALSE)

However I am getting the warning message of: ' Warning: Ignoring unknown aesthetics: z' and practically the fill is NOT the real values of the NOX.CO2 but a level OF unknown value/matterial. the image that i get is1 which is not the correct one.

I have checked the following relevant links Filled contour plot with R/ggplot/ggmap 3 but I get different errors and still not the correct fill. When using:

    ggmap(west_midlands, extent = "panel") + geom_density2d(data = noxco2_contour, aes(x = longitude, y = latitude), size = 0.3) + 
+   stat_density2d(data = noxco2_contour, 
+                  aes(x = longitude, y = latitude, group= NOX.CO2, colour= NOX.CO2), size = 0.05, 
+                  geom = "polygon") + scale_fill_gradient(low = "green", high = "red") + 
+   scale_alpha(range = c(0, 1), guide = FALSE)

I get the following: Computation failed in stat_density2d(): missing value where TRUE/FALSE needed

When I am using this code

`ggmap( west_midlands, extent = "panel" ) + 
+   stat_contour(data = noxco2_contour, geom="contour", bins=20,
+                 aes(x = longitude, y = latitude, z = NOX.CO2, fill = ..level.. ) ) +
+   scale_fill_continuous(name = "NOx(ppb)/CO2(ppm)", low = "yellow", high = "red" )

I am getting this Computation failed instat_contour(): Contour requires singlezat each combination ofxandy`.

I really appreciate any help

Many thanks, Bill

Community
  • 1
  • 1
V.MAT
  • 55
  • 2
  • 10
  • 1
    Without a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) it's hard to provide help. – Sandy Muspratt Jan 19 '17 at 00:23
  • looks like you have multiple NOX.CO2 measurements for a given latitude/longitude. You probably need to average them first. – Richard Telford Jan 19 '17 at 09:37
  • @Sandy Dataset can be found: https://www.dropbox.com/s/cs8q1y69cos57ad/NOX.CO2.csv?dl=0 – V.MAT Jan 19 '17 at 10:12

0 Answers0