簡體   English   中英

如何制作堆積面積圖?

[英]How can I make a stacked area chart?

我正在嘗試制作堆積區域圖表:

library(ggplot2)

ggplot(data, aes(x = variable, y = value, fill = term)) +
   geom_area()

但這導致了一個空白的情節。

空白情節

預期的情節(例子)

預期

我怎樣才能做到這一點?

data <- structure(list(term = c("models", "percentiles", "models:percentiles", 
                                "models", "percentiles", "models:percentiles", 
                                "models", "percentiles", "models:percentiles"), 
                       variable = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), 
                                            .Label = c("R2", "R5", "R10"), class = "factor"), 
                       value = c(0.435697205847009, 0.533615307749147, 0.0306874864038442, 
                                 0.441369621882273, 0.520198994695284, 0.0384313834224421, 
                                 0.394491546635206, 0.579421546902868, 0.0260869064619254)), 
                  row.names = c(NA, -9L), class = "data.frame")

你只是錯過了group審美:

ggplot(data, aes(x = variable, y = value, group = term, fill = term)) +
    geom_area(color = "black")

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM