grantmcdermott / grantmcdermott/tinyplot
Summary statistics (mean, median, ...) in type_violin?
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 427
- Forks
- 25
- Avg merge
- 22h 54m
- Merged PRs (30d)
- 28
Description
Is there a sufficiently easy way to add summary statistics like mean or median to violin plots? If not, then maybe this could be added to type_violin() itself?
At first, I thought that type_summary() could be used for this but this is not fully straightforward because it
- does not yet support factor
xvariables, see #436 - handles
byvariables without juxtaposition
Examples:
In the case with numeric x the violin and the points are misaligned (see left panel) because type_violin always treats x as factor and type_summary always expects numeric:
tinyplot(len ~ dose, data = ToothGrowth, fill = 0.2, type = "violin")
tinyplot_add(type = type_summary(median, type = "p"))
Using a factor x is currently not possible in type_summary:
tinyplot(len ~ factor(dose), data = ToothGrowth, fill = 0.2, type = "violin")
tinyplot_add(type = type_summary(median, type = "p"))
## Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, :
## 'range' not meaningful for factors
Only when the numeric values are 1, ..., k then violin and summary points are aligned (center panel):
tinyplot(len ~ as.numeric(as.factor(dose)), data = ToothGrowth, fill = 0.2, type = "violin")
tinyplot_add(type = type_summary(median, type = "p"))
However, even in that case, by groups are handled differently with vs without juxtaposition (right panel):
tinyplot(len ~ as.numeric(as.factor(dose)) | supp, data = ToothGrowth, fill = 0.2, type = "violin", legend = FALSE)
tinyplot_add(type = type_summary(median, type = "p"))
I guess this would indicate that adding some summary option to type_violin directly would be best?
Aside: Setting pch does not seem to be supported in type_summary?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the type_violin() and type_summary() entry points, then reproduce the ToothGrowth examples in the issue and review the factor-x discussion in #436. Clarify whether summaries belong in type_violin() or type_summary(), including factor x, by grouping, juxtaposition, and pch behavior. Done means the chosen interface aligns summaries with violins and has coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100