ggplot 中的未填充区域 geom_area

Unfilled area in ggplot geom_area

我正在尝试用 ggplot2geom_area 做一个情节。填充由变量设置。由于某种原因,只有 'outer' 组被填充。我也不知道如何填充内部区域。

似乎出现了同样的问题,但没有给出如何解决的答案。

下面是我使用的代码和结果图的最小示例:

我正在使用 R 3.3 和 ggplot2_2.1.0

如有任何帮助,我们将不胜感激。

df <- data.frame(month = seq(from = as.Date("2016-01-01"), to = as.Date("2016-12-31"), by = "month"), 
             type = c(rep("past", times = 5), "current", rep("future", times = 6)), 
             amount = c(seq(from = 100, to = 1200, by = 100)))

df$type <- factor(df$type, levels = c("past", "current", "future"))


ggplot(data = df, aes(x = month, y = amount, fill = type)) + 
  geom_area()

我在 "current" 值周围添加了 2 个时间点以生成一个区域。问题是只有一个点无法绘制区域。

library(ggplot2)

df <- data.frame(month = seq(from = as.Date("2016-01-01"), to = as.Date("2016-12-31"), by = "month"), 
                 type = c(rep("past", times = 5), "current", rep("future", times = 6)), 
                 amount = c(seq(from = 100, to = 1200, by = 100)))

df <- rbind(df[1:5, ], 
            data.frame(month = as.Date(c("2016-05-15", "2016-06-15")),
                       type  = c("current", "current"),
                       amount = c(550, 650)),
            df[7:12, ])

df$type <- factor(df$type, levels = c("past", "current", "future"))


ggplot(data = df, aes(x = month, y = amount, fill = type)) + 
geom_area()