Create non-overlapping stacked area plot with ggplot2

前端 未结 1 1218
礼貌的吻别
礼貌的吻别 2020-12-31 21:32

I have some data scraped and processed from the web in this form:

>head(dat)
  count  name          episode    percent
1   309   don 01-a-little-kiss 0.27         


        
相关标签:
1条回答
  • 2020-12-31 22:31

    That was interesting. You're missing a single row (Lane didn't appear in Tea Leaves...?), so

    dat2 <- rbind(dat,data.frame(count = 0,name = 'lane',
                        episode = '02-tea-leaves',percent = 0))
    
    ggplot(arrange(dat2,name,episode), aes(x = episode,y = percent)) + 
      geom_area(aes(fill=name,group = name), position='stack')
    

    enter image description here

    appears to work. But it had to be in the right order as well, and I'm not entirely sure why.

    0 讨论(0)
提交回复
热议问题