Stacked bar chart in R (ggplot2) with y axis and bars as percentage of counts

前端 未结 1 1099
感情败类
感情败类 2020-11-30 02:38

I\'m a novice with ggplot2 and have a question about generating a stacked bar plot. I checked the book and the dedicated webpage, but can\'t solve the problem. I have two fa

相关标签:
1条回答
  • 2020-11-30 03:05

    For the first graph, just add position = 'fill' to your geom_bar line !. You don't actually need to scale the counts as ggplot has a way to do it automatically.

    ggplot(dat, aes(x = fruit)) + geom_bar(aes(fill = variable), position = 'fill')
    
    0 讨论(0)
提交回复
热议问题