Stacked Area Chart in Plot.ly and R

前端 未结 1 747
情书的邮戳
情书的邮戳 2021-01-20 18:48

Plot.ly has a tutorial on this for Python:

# Add original data
x=[\'Winter\', \'Spring\', \'Summer\', \'Fall\']

y0_org=[40, 80, 30, 10]
y1_org=[20, 10, 10,          


        
相关标签:
1条回答
  • 2021-01-20 19:04

    This is how I got it:

    library(plotly)
    
    x <- c('Winter', 'Spring', 'Summer', 'Fall')
    y0 <- c(40, 80, 30, 10)
    y1 <- c(20, 10, 10, 10)
    y2 <- c(40, 10, 60, 80)
    
    y1 <- y0 + y1
    y2 <- y1 + y2
    
    p <- ggplot() + 
      geom_area(aes(x, y2, fill = 'green')) +
      geom_area(aes(x, y1, fill = 'blue')) +
      geom_area(aes(x, y0, fill = 'red'))
    
    ggplotly(p)
    
    0 讨论(0)
提交回复
热议问题