Skip to content

Allow stacked bars for data containing negative y-values in type_barplot() #664

Description

@634523

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions