79197750

Date: 2024-11-17 17:32:16
Score: 1
Natty:
Report link

Use the option discrete = TRUE:

ggplot(df, aes(x = x, y = y)) +
  geom_density_2d_filled() +
  scale_fill_viridis(direction = -1, discrete = TRUE)

enter image description here

geom_density_2d_filled expects a discrete color scale since it bins the density into contours, so we need to tell scale_fill_viridis to provide a discrete, rather than continuous color scale.

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Eonema