Skip to content

geom_area with negative values #2803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ptoche opened this issue Aug 4, 2018 · 2 comments
Closed

geom_area with negative values #2803

ptoche opened this issue Aug 4, 2018 · 2 comments

Comments

@ptoche
Copy link

ptoche commented Aug 4, 2018

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

@clauswilke
Copy link
Member

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

@lock
Copy link

lock bot commented Jan 31, 2019

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/

@lock lock bot locked and limited conversation to collaborators Jan 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants