I am trying to create a continuous color bar in my ggplot using:
scale_color_gradient2(midpoint = 0, mid = "white",
high = muted("blue"), low = muted("red"),
guide = "colourbar", space = "Lab").
Does anyone know how to create a
symmetric color bar, that on the left goes down to -80, even tho -80 or -100 or whatever does not exist in the data.
I want to have one color for 0-10, another color for 10-20, 20-30 yet another color. I cannot make any sense of the plots when the color changes gradually.
Lets say my code is
states <- map_data("state")
states_cluster <- subset(states,
region %in% c("washington"))
data %>%
ggplot() +
geom_polygon(data = states_cluster,
aes(x = long, y = lat, group = group),
fill = "grey", color = "black") +
geom_point(aes_string(x = "long", y = "lat", color = "color_num"),
alpha = 1, size=.3) +
guides(fill = guide_colourbar(barwidth = .1, barheight = 20))+
scale_color_gradient2(midpoint = 0, mid = "white",
high = muted("blue"), low = muted("red"),
guide = "colourbar", space = "Lab")
and my data is:
data = data.table(color_num = as.integer(runif(n = 16, min = -10, max = 80)),
lat = c(47.78125, 47.78125, 47.78125,
47.78125, 47.78125, 47.78125,
47.78125, 47.78125, 47.78125,
47.78125, 47.78125, 47.78125,
47.78125, 47.78125, 47.78125,
47.78125),
long = c(-121.21875, -121.28125, -121.34375,
-121.40625, -121.46875, -121.53125,
-121.59375, -121.65625, -121.71875,
-121.78125, -121.84375, -121.90625,
-121.96875, -122.03125, -122.09375,
-122.15625))