ggplot2에 대한 도움을 주셔서 감사합니다. 막대의 레이블을 세로로 가운데에 둘 수없는 것 같습니다.
코드는 다음과 같습니다.
library(ggplot2)
Group.id <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
Type.id <- c("a", "b", "c", "d", "a", "b", "c", "d","a", "b", "c", "d")
Value <- c(4000, 3200, 9529, 3984, 7504, 1244, 8960, 1865, 1100, 1100, 0, 0)
df <- data.frame(Group.id, Type.id, Value)
ggplot(df, aes(x = Group.id, y = Value, label = Value)) +
geom_bar(stat = "identity", aes(fill = Type.id)) +
scale_fill_manual(values=c("#00AF50", "#64A70B", "#F2A900", "#C30C3E"), labels = rev(unique(df$Type.id))) +
geom_text(position = position_stack(vjust = .5), color = "#FFFFFF")
결과는 다음과 같습니다. 중앙 레이블이없는 Barplot
작은 값으로 작동하지만 어떤 이유로 더 큰 값으로 중앙에 위치하지 않습니다. 어떠한 제안?
fill = Type.id
첫 번째 aes()
호출에 넣으십시오 .
ggplot(df, aes(x = Group.id, y = Value, label = Value, fill = Type.id)) +
geom_bar(stat = "identity") +
scale_fill_manual(values=c("#00AF50", "#64A70B", "#F2A900", "#C30C3E"), labels = rev(unique(df$Type.id))) +
geom_text(position = position_stack(vjust = .5), color = "#FFFFFF")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다