The palette
argument is expecting a function which generates a palette given a single argument as input (not a palette of colours itself)
You can wrap the brewer.pal()
function in your own function with a single input.
However, the trouble you're going to face is mapping the 9 colours from brewer.pal to the 12 SA4_NAME
variables. 9 into 12 doesn't go.
This is how it would work if you had a variable with 9 different values.
library(googleway)
library(RColorBrewer)
set_key(read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY"))
myBrewerPal <- function(x) { brewer.pal(n = x, name = "Purples") }
melbourne$myVal <- sample(1:9, size = nrow(melbourne), replace = T)
googleway::google_map("") %>%
googleway::add_polygons(
data = melbourne
, polyline = "polyline"
, fill_colour = "myVal"
, palette = myBrewerPal
)

An alternative solution is to manually add a column of hex colours to melbourne
, and specify that column as the fill_colour
. Then it's up to you to make sure the colours are mapped correctly to the variables you want.
melbourne$myColours <- sample(brewer.pal(n = 9, name = "Purples"), size = nrow(melbourne), replace = T)
googleway::google_map("") %>%
googleway::add_polygons(
data = melbourne
, polyline = "polyline"
, fill_colour = "myColours"
)