Strange plot outputs from geom_raster and geom_tile

Hello everybody,

I am trying to recreate a plot similar to this which illustrates temperature variation with depth over time.

The outputs from my code did not look right. Can anyone help me? Thanks!

library(RColorBrewer)
library(dplyr)
library(ggplot2)

DF <- data.frame(
  Date = c("2000-09-26","2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08"),
  Z = c(42.74,
        42.64,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.74,42.64,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.74,42.64,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.73,42.63,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.72,
        42.62,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.72,42.62,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,
        36.24,35.63,35.02,42.71,42.61,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.7,42.6,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.7,
        42.6,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.69,42.59,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.69,42.59,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.68,42.58,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02,42.68,42.58,
        41.73,41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02),
  Temp = c(NA,7.6,
           7.56,7.51,7.49,7.48,7.48,7.48,7.48,7.48,
           7.48,7.5,7.52,7.25,7.13,NA,7.65,7.61,
           7.56,7.55,7.55,7.54,7.54,7.55,7.55,
           7.55,7.55,7.55,7.52,7.84,NA,7.76,7.68,7.6,
           7.59,7.59,7.59,7.59,7.59,7.6,7.61,
           7.66,7.77,8.01,8.4,NA,7.76,7.73,7.69,7.68,
           7.68,7.69,7.69,7.69,7.69,7.68,7.67,
           7.67,7.64,7.93,NA,7.82,7.77,7.72,7.7,7.7,
           7.7,7.7,7.7,7.62,7.65,7.68,7.73,7.88,
           8.44,NA,7.89,7.8,7.76,7.76,7.76,7.76,
           7.77,7.81,7.87,7.9,7.9,7.98,8.3,8.69,
           NA,7.87,7.83,7.78,7.74,7.74,7.74,7.75,
           7.76,7.76,7.76,7.76,7.76,7.75,7.84,NA,
           7.9,7.83,7.78,7.78,7.78,7.78,7.78,7.77,
           7.75,7.72,7.72,7.85,8.07,8.43,NA,7.8,
           7.73,7.68,7.68,7.67,7.67,7.67,7.67,7.67,
           7.67,7.67,7.68,7.69,7.73,NA,7.81,7.74,
           7.69,7.69,7.69,7.69,7.69,7.69,7.69,
           7.69,7.69,7.69,7.7,7.75,7.96,7.95,7.86,7.79,
           7.79,7.78,7.78,7.78,7.78,7.78,7.78,
           7.78,7.79,7.8,7.8,8.00,7.99,7.95,7.93,7.93,
           7.93,7.93,7.92,7.92,7.92,7.92,7.92,
           7.92,7.95,8.23,8.23,8.21,8.19,8.18,8.17,
           8.17,8.17,8.17,8.16,8.16,8.16,8.17,8.2)
)
DF

contour_plot <- ggplot(DF, aes(Date, Z)) +
  geom_raster(aes(fill = Temp), interpolate = TRUE) +
  scale_fill_gradientn(colours = rev(brewer.pal(9, 'OrRd'))) +
  theme_minimal()
contour_plot
#> Warning: Raster pixels are placed at uneven vertical intervals and will be
#> shifted. Consider using geom_tile() instead.


contour_plot_tile <- ggplot(DF, aes(Date, Z)) +
  geom_tile(aes(fill = Temp)) +
  scale_fill_gradientn(colours = rev(brewer.pal(9, 'OrRd'))) +
  theme_minimal()
contour_plot_tile

Here is a very rough version of your plot. The main point is that geom_tile() needs a width and height for the tiles. I set the width to 1 and the height to 0.61 because the data are separated by one day and most of the Z values are spaced by 0.61.

library(RColorBrewer)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
DF <- data.frame(
  Date = c("2000-09-26","2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08"),
  Z = c(42.74,
        42.64,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.74,42.64,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.74,42.64,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.73,42.63,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.72,
        42.62,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.72,42.62,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,
        36.24,35.63,35.02,42.71,42.61,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.7,42.6,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.7,
        42.6,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.69,42.59,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.69,42.59,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.68,42.58,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02,42.68,42.58,
        41.73,41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02),
  Temp = c(NA,7.6,
           7.56,7.51,7.49,7.48,7.48,7.48,7.48,7.48,
           7.48,7.5,7.52,7.25,7.13,NA,7.65,7.61,
           7.56,7.55,7.55,7.54,7.54,7.55,7.55,
           7.55,7.55,7.55,7.52,7.84,NA,7.76,7.68,7.6,
           7.59,7.59,7.59,7.59,7.59,7.6,7.61,
           7.66,7.77,8.01,8.4,NA,7.76,7.73,7.69,7.68,
           7.68,7.69,7.69,7.69,7.69,7.68,7.67,
           7.67,7.64,7.93,NA,7.82,7.77,7.72,7.7,7.7,
           7.7,7.7,7.7,7.62,7.65,7.68,7.73,7.88,
           8.44,NA,7.89,7.8,7.76,7.76,7.76,7.76,
           7.77,7.81,7.87,7.9,7.9,7.98,8.3,8.69,
           NA,7.87,7.83,7.78,7.74,7.74,7.74,7.75,
           7.76,7.76,7.76,7.76,7.76,7.75,7.84,NA,
           7.9,7.83,7.78,7.78,7.78,7.78,7.78,7.77,
           7.75,7.72,7.72,7.85,8.07,8.43,NA,7.8,
           7.73,7.68,7.68,7.67,7.67,7.67,7.67,7.67,
           7.67,7.67,7.68,7.69,7.73,NA,7.81,7.74,
           7.69,7.69,7.69,7.69,7.69,7.69,7.69,
           7.69,7.69,7.69,7.7,7.75,7.96,7.95,7.86,7.79,
           7.79,7.78,7.78,7.78,7.78,7.78,7.78,
           7.78,7.79,7.8,7.8,8.00,7.99,7.95,7.93,7.93,
           7.93,7.93,7.92,7.92,7.92,7.92,7.92,
           7.92,7.95,8.23,8.23,8.21,8.19,8.18,8.17,
           8.17,8.17,8.17,8.16,8.16,8.16,8.17,8.2)
)
DF |>  mutate(Date = ymd(Date)) |> 
ggplot(aes(Date, Z)) +
  geom_tile(aes(fill = Temp), width = 1, height = 0.61) +
  scale_fill_gradientn(colours = rev(brewer.pal(9, 'OrRd'))) +
  theme_minimal()

Created on 2022-12-16 with reprex v2.0.2

1 Like

Thank you! Is there any way to make the plot look more smooth such as turn on interpolation (similar to geom_raster)?

Not that I know of, but I have not used such plots much. Your data could be used with geom_raster, I think, if the two highest Z values were dropped.

library(RColorBrewer)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
DF <- data.frame(
  Date = c("2000-09-26","2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-26",
           "2000-09-26","2000-09-26","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27","2000-09-27",
           "2000-09-27","2000-09-27","2000-09-27",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-28",
           "2000-09-28","2000-09-28","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-29","2000-09-29",
           "2000-09-29","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-09-30","2000-09-30",
           "2000-09-30","2000-09-30","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-01","2000-10-01",
           "2000-10-01","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-02","2000-10-02","2000-10-02",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-03","2000-10-03","2000-10-03",
           "2000-10-03","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04","2000-10-04",
           "2000-10-04","2000-10-04","2000-10-04",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-05",
           "2000-10-05","2000-10-05","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06",
           "2000-10-06","2000-10-06","2000-10-06","2000-10-06",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-07","2000-10-07","2000-10-07",
           "2000-10-07","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08","2000-10-08",
           "2000-10-08","2000-10-08"),
  Z = c(42.74,
        42.64,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.74,42.64,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.74,42.64,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.73,42.63,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.72,
        42.62,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.72,42.62,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,
        36.24,35.63,35.02,42.71,42.61,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.7,42.6,42.34,
        41.73,41.12,40.51,39.9,39.29,38.68,
        38.07,37.46,36.85,36.24,35.63,35.02,42.7,
        42.6,42.34,41.73,41.12,40.51,39.9,39.29,
        38.68,38.07,37.46,36.85,36.24,35.63,
        35.02,42.69,42.59,42.34,41.73,41.12,40.51,
        39.9,39.29,38.68,38.07,37.46,36.85,36.24,
        35.63,35.02,42.69,42.59,42.34,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,37.46,
        36.85,36.24,35.63,35.02,42.68,42.58,41.73,
        41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02,42.68,42.58,
        41.73,41.12,40.51,39.9,39.29,38.68,38.07,
        37.46,36.85,36.24,35.63,35.02),
  Temp = c(NA,7.6,
           7.56,7.51,7.49,7.48,7.48,7.48,7.48,7.48,
           7.48,7.5,7.52,7.25,7.13,NA,7.65,7.61,
           7.56,7.55,7.55,7.54,7.54,7.55,7.55,
           7.55,7.55,7.55,7.52,7.84,NA,7.76,7.68,7.6,
           7.59,7.59,7.59,7.59,7.59,7.6,7.61,
           7.66,7.77,8.01,8.4,NA,7.76,7.73,7.69,7.68,
           7.68,7.69,7.69,7.69,7.69,7.68,7.67,
           7.67,7.64,7.93,NA,7.82,7.77,7.72,7.7,7.7,
           7.7,7.7,7.7,7.62,7.65,7.68,7.73,7.88,
           8.44,NA,7.89,7.8,7.76,7.76,7.76,7.76,
           7.77,7.81,7.87,7.9,7.9,7.98,8.3,8.69,
           NA,7.87,7.83,7.78,7.74,7.74,7.74,7.75,
           7.76,7.76,7.76,7.76,7.76,7.75,7.84,NA,
           7.9,7.83,7.78,7.78,7.78,7.78,7.78,7.77,
           7.75,7.72,7.72,7.85,8.07,8.43,NA,7.8,
           7.73,7.68,7.68,7.67,7.67,7.67,7.67,7.67,
           7.67,7.67,7.68,7.69,7.73,NA,7.81,7.74,
           7.69,7.69,7.69,7.69,7.69,7.69,7.69,
           7.69,7.69,7.69,7.7,7.75,7.96,7.95,7.86,7.79,
           7.79,7.78,7.78,7.78,7.78,7.78,7.78,
           7.78,7.79,7.8,7.8,8.00,7.99,7.95,7.93,7.93,
           7.93,7.93,7.92,7.92,7.92,7.92,7.92,
           7.92,7.95,8.23,8.23,8.21,8.19,8.18,8.17,
           8.17,8.17,8.17,8.16,8.16,8.16,8.17,8.2)
)

DF |> filter(Z <= 42.34) |> mutate(Date = ymd(Date)) |> 
  ggplot(aes(Date, Z)) +
  geom_raster(aes(fill = Temp), interpolate = TRUE) +
  scale_fill_gradientn(colours = rev(brewer.pal(9, 'OrRd'))) +
  theme_minimal()

Created on 2022-12-16 with reprex v2.0.2

1 Like

This sort of works but the top is now interpolated as well resulting in a flat surface. geom_tile worked better because the part that has NA data was colored grey.

Yes, I got the smooth plot by truncating the data. I do not see a way to get the interpolation yet preserve the unevenness of the data at high Z.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.