Quick examples:
palette("Tableau 10") library(plot2) # Density plot with manual colour and fill (via the 'bg' arg) with( airquality, plot2( density(Temp), by = Month, col = "white", bg = "red", grid = TRUE, legend = FALSE ) )
# Density plot with automatic, grouped colour and fill (via bg = "by") with( airquality, plot2( density(Temp), by = Month, bg = "by", # or: type = "ribbon" grid = TRUE ) )
# Note that the "filled" legend is adaptive for other types of ribbon plots. # E.g. Here we don't get a border, but rather a line in the middle. mod = lm(Temp ~ 0 + factor(Month) / Day, airquality) pred = predict(mod, interval = "confidence") with( cbind(airquality, pred), plot2( x = Day, y = fit, by = Month, ymin = lwr, ymax = upr, type = "ribbon", grid = TRUE ) )
Created on 2023-08-12 with reprex v2.0.2