0

I'm working with the following code:

library('colorspace')

blups <- brewer.pal(9, 'BuPu')

geom_tile(aes(lon, lat, fill = predicted_price), alpha = 0.8) + scale_fill_gradientn(colors = blups)

The error msg is:

Check your call of scale_fill_gradientn(). Did you correctly specify the argument colors?

I've tried various combinations of code, and the error msg is always the same.
What's going on?

Dave2e
  • 22,192
  • 18
  • 42
  • 50
CharlieS
  • 1
  • 1

1 Answers1

0

Try this: You need library(RColorBrewer)

library(RColorBrewer)
blups <- brewer.pal(9, 'BuPu')

# Example data:
  library(reshape)
  # Data 
  set.seed(8)
  m <- matrix(round(rnorm(200), 2), 10, 10)
  colnames(m) <- paste("Col", 1:10)
  rownames(m) <- paste("Row", 1:10)
  # Transform the matrix in long format
  df <- melt(m)
  colnames(df) <- c("x", "y", "value")
  
  
  library(ggplot2)
  
  ggplot(df, aes(x = x, y = y, fill = value)) +
    geom_tile()+
    scale_fill_gradientn(colors = blups)

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66