Can you force geom_ribbon to leave a space for missing values?

The following discussion begins with: How can I get geom_area () to leave a space for missing values? . It seems that geom_ribbon no longer leaves spaces for missing values. Try the reproducible example in the attached link. I can not answer this question. Can you?

+7
source share
2 answers

Looks like an error in ggplot2 , it seems that the handle_na function is handle_na , which should be added as part of a new unified way of working with NA values.

Update:

The first post here cleared a whole new ggproto to fix this, but I realized that as a one-line workaround, you can simply override the handle_na function, as I do in the code below ( # fix GeomRibbon ):

 require(dplyr) require(ggplot2) require(grid) set.seed(1) test <- data.frame(x = rep(1:10, 3), y = abs(rnorm(30)), z = rep(LETTERS[1:3], 10)) %>% arrange(x, z) test[test$x == 4, "y"] <- NA test$ymax <- test$y test$ymin <- 0 zl <- levels(test$z) for (i in 2:length(zl)) { zi <- test$z == zl[i] zi_1 <- test$z == zl[i - 1] test$ymin[zi] <- test$ymax[zi_1] test$ymax[zi] <- test$ymin[zi] + test$ymax[zi] } # fix GeomRibbon GeomRibbon$handle_na <- function(data, params) { data } ggplot(test, aes(x = x,y=y, ymax = ymax, ymin = ymin, fill = z)) + geom_ribbon() + scale_x_continuous(breaks = 1:10) 

getting:

enter image description here

+6
source

The image I received does not match yours, and something seems to have happened here. Any suggestions?

enter image description here

0
source

All Articles