Home > Net >  Create a raster using ggplot2 without .tif and .shp files
Create a raster using ggplot2 without .tif and .shp files

Time:11-17

I'm trying to create a raster using ggplot2 for cell_temperature_value but without having .shp and .tif files. Is that possible? Or do I need to find them? My data subset

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

CodePudding user response:

You can turn point data into raster data. It depends on exactly what you want the output to look like and resolution you want. For example, you could do something like:

library(ggplot2)

ggplot()  
  geom_raster(
    data = dt ,
    aes(x = LONG, y = LAT, fill = Cell_temperature_value),
    interpolate = TRUE
  )

Output enter image description here

  • Related