您可以执行类似于Adding percentage labels to a bar chart in ggplot2中的公认答案的操作。主要的区别...
堆积柱状图#旋转后的堆积柱状图 ggplot(mpg, aes(y = class)) + geom_bar(aes(fill = drv), position = position_stack(reverse = TRUE)) + theme(legend.position = "top") 旋转后的堆积柱状图百分比柱状图g + geom_bar(aes(fill = drv), position = 'fill') ...
#绘制堆积柱状图,其中x为类别,y为统计量,fill为子类别 ggplot(data = mpg) + geom_bar(mapping = aes(x = class, fill = drv), position = "stack") #绘制分组柱状图,其中x为类别,y为统计量,fill为子类别 ggplot(data = mpg) + geom_bar(mapping = aes(x = class, fill = drv), position = ...