grantmcdermott / grantmcdermott/tinyplot
Allow stacked bars for data containing negative y-values in `type_barplot()`
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 427
- Forks
- 25
- Avg merge
- 22h 54m
- Merged PRs (30d)
- 28
Description
When plotting a stacked bar chart with negative values, tinyplot doesn't stack them the way ggplot2 does for example. Currently for data that contains negative y-values the following warning is shown:
Warning message:
In settings$type_data(settings, ...) :
'beside' must be TRUE if there are negative 'y' values
and the bars are put beside. For some data it would make sense to show the bars stacked even if some values are negative (e.g. balances like below):
rm(list = ls())
library(tinyplot)
library(worldbank)
library(ggplot2)
df <- wb_data(
indicator = c("BN.GSR.GNFS.CD", "BN.GSR.FCTY.CD", "BN.TRF.CURR.CD"),
country = "US"
)
# tinyplot
plt(
value ~ date | indicator_id,
data = df,
type = "barplot"
)
# ggplot2
ggplot(df, aes(fill=indicator_id, y=value, x=date)) +
geom_bar(position="stack", stat="identity")
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 at type_barplot() and the settings$type_data() path indicated by the warning, then reproduce the stacked-bar example with negative y-values. Trace how negative values force beside mode and make the result retain stacked behavior without the warning, matching the ggplot2 example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 67/100