2016-09-16 107 views
-1

enter image description here我試圖使用已緯度,經度,pH值如下數據集,以產生pH值在海洋中的空間圖:繪製pH值ggplot

head(sample) 
    Station  lat  long  pH 
1  B17 -23.49174 152.0718 8.222411 
2  B23 -23.49179 152.0718 8.199310 
3  B26 -23.49182 152.0717 8.140428 
4  B28 -23.49183 152.0717 8.100752 
5  B30 -23.49185 152.0717 8.068141 
6  B31 -23.49187 152.0717 8.048852 
7  B32 -23.49187 152.0717 8.043878 
8  B33 -23.49188 152.0717 8.052589 
9  B34 -23.49189 152.0717 8.085398 
10 B35 -23.49191 152.0717 8.092179 
11 B36 -23.49191 152.0717 8.103831 
12 B38 -23.49194 152.0717 8.195493 
13 B40 -23.49194 152.0717 8.289563 
14 B43 -23.49197 152.0717 8.305461 
15 B49 -23.49202 152.0717 8.319335 
16 F17 -23.49180 152.0720 8.019838 
17 F29 -23.49194 152.0719 7.827754 
18 F31 -23.49194 152.0719 7.906839 
19 F31.5 -23.49195 152.0720 7.935676 
20 F32.5 -23.49196 152.0720 7.120869 
21 F33 -23.49197 152.0720 7.282649 
22 F33.5 -23.49198 152.0720 7.209787 
23 F34 -23.49198 152.0720 7.185605 
24 F34.5 -23.49199 152.0719 7.237628 
25 F37 -23.49200 152.0719 7.657356 
26 F49 -23.49206 152.0719 8.223883 
27 M17 -23.49178 152.0719 8.161814 
28 M25 -23.49185 152.0718 7.981371 
29 M29 -23.49187 152.0718 7.882754 
30 M31 -23.49188 152.0718 7.904225 
31 M32 -23.49188 152.0718 7.940181 
32 M33 -23.49188 152.0718 8.050878 
33 M34 -23.49190 152.0718 8.129610 
34 M35 -23.49191 152.0718 8.168780 
35 M37 -23.49193 152.0718 8.182910 
36 M41 -23.49197 152.0718 8.208416 
37 M49 -23.49204 152.0718 8.197651 

我使用ggplot並能產生繪製各個位置的圖形,但我無法弄清楚它爲什麼不在位置之間進行插值以顯示漸變。我嘗試過geom_raster(interpolate=TRUE)geom_tile,但都不能在點之間進行插值。這是因爲點太稀疏了嗎?或者我錯過了什麼?謝謝!

setwd("~/OTI/OTI 2016/R") 
library(maps) 
library(ggplot2) 
library(RColorBrewer) # for brewer.pal(...) 

sample<-read.csv(file="Station locations 2016.csv", header=TRUE, sep=",", strip.white=T) 

ggplot(data = sample, aes(x = long, y = lat, fill = pH)) + 
    geom_raster(interpolate = TRUE) + 
    scale_fill_gradientn(colours = rev(rainbow(7)), na.value = NA) + 
    theme_bw() + 
    coord_fixed() + 
    geom_point(colour = "red") 
+0

它將幫助,如果你能提供數據的重複的例子... –

+0

而且這將是很好,向我們展示你已經產生的電流地圖。 –

+0

我已經包含上面的數據並上傳了當前地圖。謝謝! – Rebecca

回答

1

嘗試stat_density2d(geom="raster", aes(fill = ..density..), contour = FALSE)

+0

這產生了一個插值圖,但是stat_density2d沒有繪製出採樣點的密度而是與這些點相關的值? (在這種情況下,pH值) – Rebecca

+0

@Rebecca也許看到https://stackoverflow.com/questions/35593967/contour-levels-corresponding-to-variable-levels-in-ggplot2 –