library(ggpointdensity)
library(viridis)
ggplot(data = diamonds, mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw() +
facet_grid(~ cut, scales = 'free')
Notice from the result below, all the facets are colored based on one common global density scale.
How can I force such that each facet has their own scale, therefore would be colored based on only their number of data points, not relative to the other data points from other facet.
My current not so optimize solution is to use patchwork
library(patchwork)
r1 <- ggplot(data = diamonds %>% filter(cut == 'Fair'), mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw()
r2 <- ggplot(data = diamonds %>% filter(cut == 'Good'), mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw()
r3 <- ggplot(data = diamonds %>% filter(cut == 'Very Good'), mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw()
r4 <- ggplot(data = diamonds %>% filter(cut == 'Premium'), mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw()
r5 <- ggplot(data = diamonds %>% filter(cut == 'Ideal'), mapping = aes(x = jitter(carat), y = jitter(price))) +
geom_pointdensity(method = 'default') +
scale_color_viridis() + theme_bw()
r1 + r2 + r3 + r4 + r5