我正在尝试使用具有纬度,长度,pH值的数据集生成海洋pH值的空间图,如下所示:
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 :(得分:1)
尝试stat_density2d(geom="raster", aes(fill = ..density..), contour = FALSE)