Skip to content

geom_area with missing data issue #2720

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
space-echo opened this issue Jun 27, 2018 · 3 comments
Closed

geom_area with missing data issue #2720

space-echo opened this issue Jun 27, 2018 · 3 comments

Comments

@space-echo
Copy link

Hey,

I think I found an issue with geom_area. I think it relates to this issue ##280, although the problem looks like it might be different to the previous problem. Have used the same dataframe as from issue above.

You can see that although the bar plot shows nothing for g = B at point x = 3, the area plot seems to make it look like it's actually g = A that is missing data. See chart and code below.

screen shot 2018-06-27 at 23 53 17

dat <- data.frame(
  g=rep(LETTERS[1:3], each=4),
  x=rep(1:4, 3),
  y=rep(3:14))

# Remove row with g=B, x=3 
dat <- dat[!(dat$g == "B" & dat$x == 3), ] 

g <- ggplot(dat, aes(x=x, y=y, fill=g)) 

p1 <- g + geom_bar(stat = "identity")
p2 <- g + geom_area(stat = "identity")

output <- gridExtra::grid.arrange(p1, p2, ncol = 2)
@batpigandme
Copy link
Contributor

As noted in the thread to which you referred, the problem here is one of automatic interpolation — obviously this isn't the desired behaviour, but the area chart is, in effect, treating your x-axis as continuous.

@clauswilke
Copy link
Member

geom_area() is drawing exactly the data it is given, so the behavior is correct. To get the plot you want, you'll have to set the y value of the missing cases to 0.

library(ggplot2)
dat <- data.frame(
  g=rep(LETTERS[1:3], each=4),
  x=rep(1:4, 3),
  y=rep(3:14))

dat[dat$g == "B" & dat$x == 3, ]$y <- 0 
ggplot(dat, aes(x=x, y=y, fill=g)) + geom_area(stat = "identity")

Created on 2018-06-29 by the reprex package (v0.2.0).

@lock
Copy link

lock bot commented Dec 26, 2018

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 Dec 26, 2018
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

3 participants