1
ggplot2에서 누적 막대 그래프를 생성합니다. 두 가지 질문이 있습니다 :누적 막대 그래프 위에 총계 추가
y 축 및 데이터 레이블의 배율을 1 대신 1000 단위로 표시하려면 어떻게 변경합니까? 카운트 합계를 각 막대 위에 표시 할 수있는 방법이 있습니까? 예 : 막대 1 위에 굵게 표시 94 (천), 막대 2 위에 122 (천) 표시).
library(ggplot2)
library(dplyr)
#Creating the dataset
my.data <- data.frame(dates = c("1/1/2014", "1/1/2014", "1/1/2014", "1/1/2014", "1/1/2014", "2/1/2014", "2/1/2014", "2/1/2014", "2/1/2014", "2/1/2014"),
fruits=c("apple", "orange", "pear", "berries", "watermelon", "apple", "orange", "pear", "berries", "watermelon"),
count=c(20000, 30000, 40000, 2000, 2000, 30000, 40000, 50000, 1000, 1000))
#Creating a positon for the data labels
my.data <-
my.data %>%
group_by(dates) %>%
mutate(pos=cumsum(count)-0.5*count)
#Plotting the data
ggplot(data=my.data, aes(x=dates, y=count, fill=fruits))+
geom_bar(stat="identity")+
geom_text(data=subset(my.data, count>10000), aes(y=pos, label=count), size=4)