grantmcdermott / tinyplot

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

Combine multiple `type`s in a list? #93

Closed grantmcdermott closed 9 months ago

grantmcdermott commented 9 months ago

Would be cool if we could do something like:

plot2(1:10, type = list("p", "l"))

Obviously, for this particular case we could just use type = o as a workaround. But I'm thinking more as convenience feature for combining, say, points with ribbon plots. (And, as opposed, to calling another plot with add= TRUE.)

... OTOH are there many cases where this would be useful? Especially given that, for some of the canonical "combination" plots that I can think of (e.g., regression best-fit line with raw data points), the different types actually require different y values.

zeileis commented 9 months ago

The main combination that I'm missing from type is "h" with "p" in oder to obtain "lollipop" style plots. I like these for discrete distributions or short time series of counts etc. For example:

x <- 0:7
p <- dpois(x, lambda = 1.4)
plot(x, p, type = "h")
points(x, p, pch = 19)

Poisson(1.4) density

But maybe it is overkill to support a vector or list for type. Also, this type vector is only simple to process if other arguments (like col, lwd, lty, pch, etc.) are handled in the same way for both types. Otherwise the specification of arguments may become rather complex.

An alternative for the particular combination of "h" and "p" would be to support a new type = "i" (where "i" resembles the line with a point on top).

grantmcdermott commented 9 months ago

Oooh, I like the idea of a type = "i". The perfect symbol for it.

I take your wider point too about rolling our own combination types internally and this being potentially less complicated. Maybe type = "plm" for points + lm() prediction line, for example?

zeileis commented 9 months ago

Good idea. I would use either type = "%" (to resemble points with a line through it) or type = "f" for a model fit. Then we can potentially provide different kinds of fits, e.g., "lm", "loess", "gam", etc.

grantmcdermott commented 9 months ago

These are great ideas. Let me close this issue and instead open up a dedicated "Supported types" issue, where we can list all of the ideas in one place (and tick them off as we add them.)

grantmcdermott commented 9 months ago

Update: It's here https://github.com/grantmcdermott/plot2/issues/97

Please feel free to edit/add as you see fit @zeileis.

The type="i" idea might be a nice and simple one to roll in before the plot2 v0.0.4 release if you have time. No rush, though.

(RE: v0.0.4. I'm taking a crack at formula support for facets, since that's the last thing I want to add before release. But I'm setting myself a deadline of only a few days, since this new version has been delayed long enough by #94.)