grantmcdermott / tinyplot

Lightweight extension of the base R graphics system
https://grantmcdermott.com/tinyplot
Apache License 2.0
208 stars 7 forks source link

Make facet formulas compatible with density plots #104

Closed grantmcdermott closed 5 months ago

grantmcdermott commented 5 months ago

Fixes #103.

The problem examples from that issue all work properly now.

pkgload::load_all("~/Documents/Projects/plot2")
#> ℹ Loading plot2

aq = airquality
aq$hot = ifelse(aq$Temp>=75, "hot", "cold")
aq$windy = ifelse(aq$Wind>=15, "windy", "calm")

with(
  aq,
  plot2(
    Ozone, 
    type = "density",
    facet = windy ~ hot,
    fill = "by",
    grid = TRUE, frame = FALSE, 
    main = "Ozone pollution is worse on hot, calm days"
  )
)

plot2(
  ~ Ozone,
  data = aq, 
  type = "density",
  facet = windy ~ hot,
  fill = "by",
  grid = TRUE, frame = FALSE, 
  main = "Ozone pollution is worse on hot, calm days"
)

plot2(
  ~ Ozone,
  data = subset(aq, !is.na(Ozone)), 
  type = "density",
  facet = windy ~ hot,
  fill = "by",
  grid = TRUE, frame = FALSE, 
  main = "Ozone pollution is worse on hot, calm days"
)

Created on 2024-01-25 with reprex v2.0.2