具有2个刻度的嵌套堆积条形图:ggplot2 R

时间:2019-04-20 23:35:04

标签: r ggplot2

我想将y轴缩放为percent.x而不是percent.y。但是,当我这样做时,比例尺是不正确的。

"PID","severity","percentage.x","sideEffectScore","n","percentage.y"
189,"moderate",40,"1",25,69.44
189,"moderate",40,"2",5,13.89
189,"moderate",40,"3",5,13.89
189,"moderate",40,"4",1,2.78
189,"severe",26.67,"1",8,33.33
189,"severe",26.67,"2",9,37.5
189,"severe",26.67,"3",7,29.17
189,"transient",33.33,"1",12,40
189,"transient",33.33,"2",8,26.67
189,"transient",33.33,"3",8,26.67
189,"transient",33.33,"4",2,6.67
library(ggplot2)

df <- read.csv("testing.csv",
               header = T)

ggplot(testing, aes(severity, percentage.y)) +
        geom_bar(aes(fill = sideEffectScore), stat="identity") 
y.y轴的百分比为y的总和为100%。 enter image description here

但是,percent.x的总和不是100%,而是“应该”且堆叠不正确。 enter image description here

0 个答案:

没有答案