Skip to content

geom_area with negative values #2803

Closed
Closed

Description

@ptoche

I recently reported changes in the order in which geom_area stacks layers. Adding the position = position_stack(reverse = TRUE) option seemed to be enough to revert to the "old" (undated) behaviour. I am now seeing some unexpected behaviour. Immediately below is my plot of 2 years ago, followed by a reprex of the plot now:

As I was preparing this issue, I noticed a possibly related issue posted 4 hours ago.

Here is the desired plot of 2 years ago:

figure_3_1

Below is the reprex of today's plot:

library(reprex)

# Data
df <- structure(list(Year = c(1700, 1750, 1810, 1850, 1880, 1910, 1920, 
1950, 1970, 1990, 2010, 1700, 1750, 1810, 1850, 1880, 1910, 1920, 
1950, 1970, 1990, 2010, 1700, 1750, 1810, 1850, 1880, 1910, 1920, 
1950, 1970, 1990, 2010, 1700, 1750, 1810, 1850, 1880, 1910, 1920, 
1950, 1970, 1990, 2010), variable = structure(c(2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("National capital (private + public)", 
"Agricultural land", "Housing", "Other domestic capital", "Net foreign capital", 
"Public capital", "Public assets", "Public debt", "Private capital"
), class = "factor"), value = c(4.14, 3.6, 3.09, 2.43, 1.72, 
0.33, 0.38, 0.17, 0.1, 0.06, 0.03, 1.24, 1.07, 1.12, 1.04, 1.22, 
1.45, 0.71, 0.94, 1.24, 1.86, 3, 1.66, 2.14, 2.57, 3.08, 2.79, 
3.25, 0.95, 1.3, 1.93, 2.74, 2.4, 0, 0.05, 0.1, 0.39, 1, 1.76, 
0.84, -0.06, 0.06, -0.04, -0.2)), row.names = c(NA, -44L), class = "data.frame")

# Packages
library(ggplot2)
library(scales)
library("RColorBrewer")

# Plot with geom_area
ggplot(data = df, aes(x = Year, y = value, group = variable, fill = variable)) + geom_area(position = position_stack(reverse = TRUE), alpha = 0.7, show.legend = TRUE) + ylab("Value of national capital (% national income)") + xlab(NULL) + scale_x_continuous(breaks = seq(1700, 2020, by = 50)) + scale_y_continuous(labels = percent, breaks = seq(0, 8, by = 1)) + scale_fill_brewer(palette = "Blues") + theme(legend.position = c(0.25, 0.25), legend.title = element_blank()) + guides(shape = guide_legend(ncol = 1))

reprex() 
#> Rendering reprex...
#> Rendered reprex is on the clipboard.

Created on 2018-08-04 by the reprex package (v0.2.0).

Activity

  1. clauswilke commented on Aug 4, 2018

    @clauswilke
    Member

    I don't see how this differs from #2802. Let's keep the conversation in one issue.

  2. lock commented on Jan 31, 2019

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  3. locked and limited conversation to collaborators on Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions