使用不带 .tif 和 .shp 文件的 ggplot2 创建栅格
Create a raster using ggplot2 without .tif and .shp files
我正在尝试使用 ggplot2
为 cell_temperature_value
创建光栅,但没有 .shp 和 .tif 文件。那可能吗?或者我需要找到他们吗?我的数据子集
dt<-structure(list(Cell_temperature_value = c(3.82969190920466, 2.95279360047462,
2.07589529174459, 1.19899698301455, 0.322098674284518, -0.554799634445516,
-1.43169794317555, -2.30859625190558, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3, 4.91461274282071, 4.03771443409067, 3.16081612536064,
2.28391781663061, 1.40701950790057, 0.530121199170537, -0.346777109559497,
-1.22367541828953, -2.10057372701957, -2.9774720357496, -3, -3,
-3, -3, -3, -3, -3, -3, 5.99953357643665, 5.12263526770661, 4.24573695897658,
3.36883865024655, 2.49194034151651, 1.61504203278648, 0.738143724056442,
-0.138754584673592, -1.01565289340363, -1.89255120213366, -2.76944951086369,
-3, -3, -3), LAT = c(29.570000000321, 29.750000000321, 29.930000000321,
30.110000000321, 30.290000000321, 30.470000000321, 30.650000000321,
30.830000000321, 31.010000000321, 31.190000000321, 31.370000000321,
31.550000000321, 31.730000000321, 31.910000000321, 32.090000000321,
32.270000000321, 32.450000000321, 32.630000000321, 29.570000000321,
29.750000000321, 29.930000000321, 30.110000000321, 30.290000000321,
30.470000000321, 30.650000000321, 30.830000000321, 31.010000000321,
31.190000000321, 31.370000000321, 31.550000000321, 31.730000000321,
31.910000000321, 32.090000000321, 32.270000000321, 32.450000000321,
32.630000000321, 29.570000000321, 29.750000000321, 29.930000000321,
30.110000000321, 30.290000000321, 30.470000000321, 30.650000000321,
30.830000000321, 31.010000000321, 31.190000000321, 31.370000000321,
31.550000000321, 31.730000000321, 31.910000000321), LONG = c(35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152), fecha = structure(c(14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610), class = "Date"), cellID = c(1, 19, 37, 55, 73, 91, 109,
127, 145, 163, 181, 199, 217, 235, 253, 271, 289, 307, 2, 20,
38, 56, 74, 92, 110, 128, 146, 164, 182, 200, 218, 236, 254,
272, 290, 308, 3, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183,
201, 219, 237), year = c(2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010
)), row.names = c(NA, -50L), class = c("tbl_df", "tbl", "data.frame"
))
您可以将点数据转换为栅格数据。这完全取决于您希望输出的外观和所需的分辨率。例如,您可以这样做:
library(ggplot2)
ggplot() +
geom_raster(
data = dt ,
aes(x = LONG, y = LAT, fill = Cell_temperature_value),
interpolate = TRUE
)
输出
我正在尝试使用 ggplot2
为 cell_temperature_value
创建光栅,但没有 .shp 和 .tif 文件。那可能吗?或者我需要找到他们吗?我的数据子集
dt<-structure(list(Cell_temperature_value = c(3.82969190920466, 2.95279360047462,
2.07589529174459, 1.19899698301455, 0.322098674284518, -0.554799634445516,
-1.43169794317555, -2.30859625190558, -3, -3, -3, -3, -3, -3,
-3, -3, -3, -3, 4.91461274282071, 4.03771443409067, 3.16081612536064,
2.28391781663061, 1.40701950790057, 0.530121199170537, -0.346777109559497,
-1.22367541828953, -2.10057372701957, -2.9774720357496, -3, -3,
-3, -3, -3, -3, -3, -3, 5.99953357643665, 5.12263526770661, 4.24573695897658,
3.36883865024655, 2.49194034151651, 1.61504203278648, 0.738143724056442,
-0.138754584673592, -1.01565289340363, -1.89255120213366, -2.76944951086369,
-3, -3, -3), LAT = c(29.570000000321, 29.750000000321, 29.930000000321,
30.110000000321, 30.290000000321, 30.470000000321, 30.650000000321,
30.830000000321, 31.010000000321, 31.190000000321, 31.370000000321,
31.550000000321, 31.730000000321, 31.910000000321, 32.090000000321,
32.270000000321, 32.450000000321, 32.630000000321, 29.570000000321,
29.750000000321, 29.930000000321, 30.110000000321, 30.290000000321,
30.470000000321, 30.650000000321, 30.830000000321, 31.010000000321,
31.190000000321, 31.370000000321, 31.550000000321, 31.730000000321,
31.910000000321, 32.090000000321, 32.270000000321, 32.450000000321,
32.630000000321, 29.570000000321, 29.750000000321, 29.930000000321,
30.110000000321, 30.290000000321, 30.470000000321, 30.650000000321,
30.830000000321, 31.010000000321, 31.190000000321, 31.370000000321,
31.550000000321, 31.730000000321, 31.910000000321), LONG = c(35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.2899999657152, 35.2899999657152, 35.2899999657152,
35.2899999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.4699999657152,
35.4699999657152, 35.4699999657152, 35.4699999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152, 35.6499999657152, 35.6499999657152, 35.6499999657152,
35.6499999657152), fecha = structure(c(14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610, 14610,
14610), class = "Date"), cellID = c(1, 19, 37, 55, 73, 91, 109,
127, 145, 163, 181, 199, 217, 235, 253, 271, 289, 307, 2, 20,
38, 56, 74, 92, 110, 128, 146, 164, 182, 200, 218, 236, 254,
272, 290, 308, 3, 21, 39, 57, 75, 93, 111, 129, 147, 165, 183,
201, 219, 237), year = c(2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010
)), row.names = c(NA, -50L), class = c("tbl_df", "tbl", "data.frame"
))
您可以将点数据转换为栅格数据。这完全取决于您希望输出的外观和所需的分辨率。例如,您可以这样做:
library(ggplot2)
ggplot() +
geom_raster(
data = dt ,
aes(x = LONG, y = LAT, fill = Cell_temperature_value),
interpolate = TRUE
)
输出