grantmcdermott / grantmcdermott/tinyplot

Potential `type_summary` improvements

Open
#696 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
427
Forks
25
Avg merge
22h 54m
Merged PRs (30d)
28

Description

Working towards a fix of #441 and #471, I've identified four potential improvements to type_summary() that we should consider making:

1. type_summary() should call aggregate() instead of ave().

There's no need to retain the original, full data length as long as we retain the unique values of x. Worse, we're currently "overplotting" each x point with multiple versions of the same y value. No brainer to fix.

2. type_summary() should accept a dodge argument

For grouped summaries that share the same x values. This is a necessary step towards resolving both #441 and #471. Another no-brainer IMO.

3.type_summary() should be able to produce text

In other words, it should accept a type = "text" argument (with appropriate routing to text() instead of lines() for drawing). Necessary for #471 and any other cases where we want to add textual summaries to base plots that aggregate multiple-y-per-x cases via a FUN/fun transformation. For example, aggregated barplots:

plt(mpg ~ gear, data = mtcars, type = "barplot")
plt_add(type = type_summary())
plt_add(type = type_text(pos = 3, xpd = NA))

Manual version of what we want:

plt(mpg ~ gear, data = mtcars, type = "barplot")
plt_add(data = round(aggregate(mpg ~ gear, data = mtcars, FUN = mean), 1),
        type = type_text(pos = 3, xpd = NA))

Of course, as suggested by my manual example, an alternative approach is allowing type_text() itself to take an aggregating function argument. But this feels like scope creep and more clunky to me.

4. type_summary(type = "p") should be the default (maybe?)

This one I'm a little less confident about, especially since it would be a breaking change from the current default, i.e., type_summary(type = "l"). But I think it would be more consistent with (typical) plotting defaults. Similarly, lines (usually) don't make sense when you are layering on top of plots with a categorical x-axis, e.g.:

library("tinyplot")
plt(flipper_len ~ species, data = penguins,  type = "violin")
plt_add(type = "summary")

versus

plt(flipper_len ~ species, data = penguins, type = type_violin())
plt_add(type = type_summary(type = "p"))

A similar argument could be made for type_function(). @vincentarelbundock I'd be curious on your thoughts (since you added this latter type).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementation of type_summary() and review the discussions in #441 and #471. Compare the current ave() and lines() behavior with the proposed aggregate(), dodge, text, and default-type options. Done requires an agreed scope and settled behavior for the selected API changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.