1

I am trying to make map to show the concentrations of Chromium recorded in topsoil in Scotland (n = 1000). The following is a sub-set of the data:

     Easting Northing Concentration
1  -4.327230 55.94000      1.913814
2  -4.336588 55.77886      1.408240
3  -4.334057 55.93637      1.798651
4  -4.340633 55.94451      1.629410
5  -4.341627 55.77247      1.382017
6  -4.354362 55.78004      1.432969
7  -4.327912 55.94871      1.488551
8  -4.301948 55.77286      1.278754
9  -4.317669 55.77715      1.465383
10 -4.266635 55.77981      1.793092
11 -4.349507 55.77358      1.336460
12 -4.331458 55.92509      1.546543
13 -4.360420 55.77211      1.720986
14 -4.316048 55.93779      1.876795
15 -4.348813 55.92620      1.637490
16 -4.358550 55.92574      1.460898
17 -4.271819 55.88522      2.011570
18 -4.350699 55.93884      1.385606
19 -4.323065 55.78208      1.620136
20 -4.305748 55.94769      1.463893
21 -4.324094 55.76453      1.416641
22 -4.311998 55.77294      1.390935
23 -4.295788 55.77657      1.378398
24 -4.351286 55.94323      1.485721
25 -4.344118 55.78473      1.623249
26 -4.358147 55.93492      1.454845
27 -4.310889 55.78653      1.372912
28 -4.270665 55.77506      1.706718
29 -4.341747 55.78244      1.561101
30 -4.312615 55.93929      1.521138
31 -4.330014 55.78626      1.564666
32 -4.328320 55.95283      2.313656
33 -4.334340 55.93043      2.007748
34 -4.317788 55.76303      1.309630
35 -4.342244 55.93936      1.680336
36 -4.351105 55.94818      1.673942
37 -4.351354 55.93379      1.396199
38 -4.318706 55.93135      1.854913
39 -4.315999 55.93428      1.361728
40 -4.326163 55.78588      1.646404
41 -4.302010 55.78203      2.023664
42 -4.318585 55.78720      1.305351
43 -4.304388 55.94097      1.465383
44 -4.309106 55.93414      1.539076
45 -4.297275 55.77474      1.503791
46 -4.298785 55.93290      1.447158
47 -4.326837 55.77311      1.555094
48 -4.342423 55.92641      1.338456
49 -4.332528 55.77228      1.491362
50 -4.347461 55.78197      1.426511

str(dat.tmp)

   'data.frame':    50 obs. of  3 variables:
 $ Easting      : num  -4.33 -4.34 -4.33 -4.34 -4.34 ...
 $ Northing     : num  55.9 55.8 55.9 55.9 55.8 ...
 $ Concentration: num  1.91 1.41 1.8 1.63 1.38 ...

This is the code I am currently using to produce the concentrations on a map of Glasgow:

qmap(location="glasgow", maptype = "terrain",zoom=10,color="bw"
     ,extent="panel",
     maprange=FALSE) + 
  stat_contour(data = dat.tmp, geom="polygon", 
               aes(x =Easting, y = Northing, z = Concentration
                   , fill = ..level.. ) ) +
  scale_fill_continuous(name = "Cu (mg/kg)", low = "yellow", high = "red" )

When executing, this is returning:

Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0
In addition: Warning message:
Not possible to generate contour data 

This is a similar issue to a previous post - the map / plot I am trying create is very similar too.

Filled contour plot with R/ggplot/ggmap

Any help would be greatly appreciated - thank you.

Community
  • 1
  • 1
user3310449
  • 33
  • 1
  • 5
  • 1
    You map `z = glas.dat.A_Cu_mg_kg`, but it's not present in the data set, is this just a typo? – tonytonov Sep 05 '14 at 07:54
  • sorry, yes it's a typo - it is actually 'z = Concentration' in my script that gives the error above. any thoughts about what the problem might be with the typo correction? thanks :) – user3310449 Sep 05 '14 at 10:32
  • Please edit the question accordingly. It would be also helpful to narrow the issue down to a minimal data set that [reproduces](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) the error, so that anyone can copy & paste the data and the code. – tonytonov Sep 05 '14 at 10:41

1 Answers1

0

I've reproduced the error, and also spotted a warning:

Warning message: Not possible to generate contour data

A quick google points at a similar question, which is resolved by using stat_density2d instead of stat_contour:

qmap(location="glasgow", maptype = "terrain", zoom=10, color="bw", 
     extent="panel", maprange=FALSE) + 
  stat_density2d(data=dat, 
                 aes(x=Easting, y=Northing, z=Concentration, fill=..level.. ))

enter image description here

Community
  • 1
  • 1
tonytonov
  • 25,060
  • 16
  • 82
  • 98
  • Yes, I have tried that already but the contours are simply representations of the sample density based on the Easting and Northing references. To see what I mean, remove 'z=Concentration' from the code and execute. – user3310449 Sep 05 '14 at 12:20
  • Ah, alright. Anyway, there's a comment on the question that probably an equidistant grid is required. Does the accepted answer there help? – tonytonov Sep 05 '14 at 19:11