【发布时间】:2019-11-19 02:07:00
【问题描述】:
我想用ggplot,我的数据就是这样
x <- c(TRUE,FALSE,FALSE,TRUE,TRUE,FALSE) #Logical
y <- c(0,1,1,0,1,0) #Numeric
dat <- data.frame(x,y)
我想创建一个显示百分比的堆积条形图...这似乎应该是一个简单的问题,但不知何故我把它搞砸了,找不到直接的答案。
我试过了
ggplot(data = dat, aes(x = x, y = y, fill = y))+geom_bar(position = 'fill', stat = 'identity')
ggplot(data = dat, aes(x = x, y = factor(y), fill = y))+geom_bar(position = 'fill', stat = 'identity')
第二个看起来更近了,但轴将所有内容压缩到总和为 0?
【问题讨论】:
标签: r ggplot2 stacked-chart