2014-09-03 66 views
1

我想使地图显示在苏格兰(n = 1000)表土中记录的铬浓度。以下是一个子集的数据:使用ggplot绘制化学浓度

 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

您映射'z = glas.dat.A_Cu_mg_kg',但它不存在于数据集中,这只是一个错字吗? – tonytonov 2014-09-05 07:54:53

+0

对不起,是的,这是一个错字 - 它在我的脚本中实际上是'z = Concentration',它给出了上述错误。有关错字更正可能出现的问题的任何想法?谢谢:) – user3310449 2014-09-05 10:32:09

+0

请相应地编辑问题。将问题的范围缩小到最小的数据集也是有帮助的[重现](错误)(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)错误,这样任何人都可以复制和粘贴数据和代码。 – tonytonov 2014-09-05 10:41:37

回答

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

+0

是的,我已经尝试过,但轮廓仅仅是基于Easting和Northing参考的样本密度的表示形式。为了明白我的意思,从代码中删除'z = Concentration'并执行。 – user3310449 2014-09-05 12:20:08

+0

啊,好吧。无论如何,对于可能需要等距离网格的问题有一个评论。那里接受的答案有帮助吗? – tonytonov 2014-09-05 19:11:39