2016-05-31 3 views
0

막대 높이가 전체 값에 해당하는 막대 그래프를 얻고 싶습니다. 막대 자체는 부분 값에 따라 색상으로 나뉩니다. . 나는이 부분 값의 분포를 존중하지 않는 무엇을 얻을ggplot2로 plot하는 방법 data.frame의 색상 채우기가있는 geom_bar 그래프

df <- data.frame(name = c("a", "b", "c"), 
       total = c(10, 20, 30), 
       left = c(5, 10, 5), 
       middle = c(4, 5, 15), 
       right = c(1, 5, 10)) 

df <- gather(df, key, value, 3:5) 

ggplot(df, aes(x = name, y = total, fill = key)) + geom_bar(stat = "identity") 

...

+1

'y = value'는 어떨까요? – mtoto

답변

1

변경 ggplot의 값으로 총 :

ggplot(df, aes(x = name, y = value, fill = key)) + geom_bar(stat = "identity") 

대신 :

ggplot(df, aes(x = name, y = total, fill = key)) + geom_bar(stat = "identity") 
관련 문제