Ribbon Plot

Create a ribbon plot using geom_ribbon and geom_area.

geom ribbon — ggplot vs CanvasXpress

library(ggplot2)
library(canvasXpress)
# Generate data
huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
h <- ggplot(huron, aes(year))

e <- h + geom_ribbon(aes(ymin=0, ymax=level))
e
canvasXpress(e)
# Add aesthetic mappings
e <- h +
            geom_ribbon(aes(ymin = level - 1, ymax = level + 1), fill = "grey70") +
            geom_line(aes(y = level))
e
canvasXpress(e)
# The underlying stat_align() takes care of unaligned data points
df <- data.frame(
            g = c("a", "a", "a", "b", "b", "b"),
            x = c(1, 3, 5, 2, 4, 6),
            y = c(2, 5, 1, 3, 6, 7)
)
a <- ggplot(df, aes(x, y, fill = g)) +
            geom_area()

# Two groups have points on different X values.
e <- a + geom_point(size = 8) + facet_grid(g ~ .)
e
canvasXpress(e)
# stat_align() interpolates and aligns the value so that the areas can stack
# properly.
e <- a + geom_point(stat = "align", position = "stack", size = 8)
e
canvasXpress(e)
# To turn off the alignment, the stat can be set to "identity"
e <- ggplot(df, aes(x, y, fill = g)) +
            geom_area(stat = "identity")
e
canvasXpress(e)