79283364

Date: 2024-12-15 23:33:29
Score: 1
Natty:
Report link

Do this:

# Create density plot with custom colors for categories A and B
ggplot(df, aes(x = x, y = y)) +
  stat_density_2d(
    aes(fill = cat, alpha = after_stat(level)), 
    geom = "polygon",
    color = NA
  ) +
  scale_fill_manual(
    values = c("A" = "darkorange", "B" = "cyan2"),
    name = "Category",  # Legend title
    guide = "legend"
  ) +
  scale_alpha(range = c(0, 0.5), guide = "none") 

refer this for colors.

out

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