grantmcdermott / tinyplot

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

Support "area" plots #67

Closed grantmcdermott closed 10 months ago

grantmcdermott commented 10 months ago

(Where, following ggplot2, area plots are just defined as a special case of ribbon plots with ymin = 0 and ymax = y.)

While we can manually achieve this by doing something like...

with(
    airquality,
    plot2(
        x = seq_along(Temp), 
        y = Temp,
        ymin = rep(0, length(Temp)),
        ymax = Temp,
        type = "ribbon"
    )
)

... it would be cool if it could be automatically inferred when (a) type = "ribbon" and (b) ymin and ymax aren't specified. So, something like the following would offer a concise way to get the previous plot above.

with(
    airquality,
    plot2(Temp, type = "ribbon")
)
grantmcdermott commented 10 months ago

This will be trivial to implement and I'll put in a PR later today.

But one design question is whether we follow my pseudo code above (i.e. use type = "ribbon" and infer behaviour based on the absence of ymin/ymax)... OR do we rather introduce a new type = "area" to make the behaviour more explicit?

@vincentarelbundock I feel like you would have some good intuition here.

vincentarelbundock commented 10 months ago
import this

>>> Explicit is better than implicit.

Here, I kind of agree with the Zen ;)