Reverse the order of scale on the ColorBrewer

I want to use the colour brewer to set the scale of my plot. However, I would prefer to reverse the order of scale so that the lighter colour represents a cold(er) day and the darker colour would represent a hotter day.

library(tidyverse)
library(ryouwithme)
library(RColorBrewer)

rain_temp_bugs %>% # data set from RYouWithMe package
  na.omit() %>%
  filter(beachbugs > 500) %>%
  ggplot(
    aes(
      x      = rain_mm,
      y      = beachbugs,
      colour = temp_airport
    )
  ) +
  geom_point() +
  geom_smooth() +
  scale_color_distiller(palette = "YlOrBr")
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2022-01-29 by the reprex package (v2.0.1)

library(tidyverse)
# library(ryouwithme) # not found
library(RColorBrewer)

rain_temp_bugs <- readr::read_csv("https://raw.githubusercontent.com/rladiessydney/RYouWithMe/master/sydneybeaches.csv")
#> Rows: 3690 Columns: 8
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (4): Region, Council, Site, Date
#> dbl (4): BeachId, Longitude, Latitude, Enterococci (cfu/100ml)
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

# analogous to OP
rain_temp_bugs %>% # data set from RYouWithMe package
  na.omit() %>%
  # filter(beachbugs > 500) %>%
  ggplot(
    aes(
      x      = BeachId,
      y      = Latitude,
      colour = `Enterococci (cfu/100ml)`
    )
  ) +
  geom_point() +
  geom_smooth() +
  scale_color_distiller(palette = "YlOrBr")
#> `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

# analogous to OP, but order reversed
rain_temp_bugs %>% # data set from RYouWithMe package
  na.omit() %>%
  # filter(beachbugs > 500) %>%
  ggplot(
    aes(
      x      = BeachId,
      y      = Latitude,
      colour = `Enterococci (cfu/100ml)`
    )
  ) +
  geom_point() +
  geom_smooth() +
  scale_color_distiller(palette = "YlOrBr", direction = 1,)
#> `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

1 Like

This topic was automatically closed 21 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.