用ggplot绘制化学浓度

时间:2014-09-03 15:06:54

标签: r ggplot2 ggmap qmap

我正在尝试制作地图以显示苏格兰表层土壤中记录的铬浓度(n = 1000)。以下是数据的子集:

     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 ...

这是我目前用于在格拉斯哥地图上产生浓度的代码:

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" )

执行时,返回:

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

这与之前的帖子类似 - 我正在尝试制作的地图/情节也非常相似。

Filled contour plot with R/ggplot/ggmap

非常感谢任何帮助 - 谢谢。

1 个答案:

答案 0 :(得分:0)

我重现了这个错误,并发现了警告:

  

警告消息:无法生成轮廓数据

快速谷歌指向similar question,使用stat_density2d代替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