문제

나는 ggplot2를 사용하여 B로 Bullseye 차트를 만들고 있습니다. 그들은 즐거워 보이며, Bullseye 레이어의 값을 차트에 플로팅하고 싶다는 것을 제외하고는 모두가 매우 기쁘게 생각합니다. 나는 그것들을 줄거리의 오른쪽 하단 모서리 나 줄거리 마진에 넣는 것을 기쁘게 생각하지만, 나는 이것을하는 데 어려움을 겪고 있습니다.

예제 데이터는 다음과 같습니다.

critters <- structure(list(Zoo = "Omaha", Animals = 50, Bears = 10, PolarBears = 3), .Names = c("Zoo", 
"Animals", "Bears", "PolarBears"), row.names = c(NA, -1L), class = "data.frame")

그리고 그것을 음모하는 방법 :

d <- data.frame(animal=factor(c(rep("Animals", critters$Animals),
       rep("Bears", critters$Bears), rep("PolarBears", critters$PolarBears)),
       levels = c("PolarBears", "Bears", "Animals"), ordered= TRUE))
grr <- ggplot(d, aes(x = factor(1), fill = factor(animal))) +  geom_bar() +
  coord_polar() + labs(x = NULL, fill = NULL) +
  scale_fill_manual(values = c("firebrick2", "yellow2", "green3")) +
  opts(title = paste("Animals, Bears and Polar Bears:\nOmaha Zoo", sep=""))

이 플롯의 오른쪽 하단 구석에 목록을 추가하고 싶습니다.

Animals: 50
Bears: 10
PolarBears: 3

그러나 나는 방법을 알 수 없습니다. 지금까지의 노력 annotate() 부분적으로 극지 좌표에 의해 방해가되었습니다. 제목에 숫자를 추가해야한다면 그렇게해야합니다. 그러나 나는 항상 더 우아한 솔루션에 대한 희망을 가지고 있습니다. 미리 감사드립니다.

편집 : 뒤 따르는 사람들에게 중요한 메모 : Bullseye는 극지 좌표에 매핑 된 막대 플롯입니다. 막대 플롯에 대한 GGPLOT2 기본값은 현명하게 쌓기 위해 쌓입니다. 그러나 그것은 당신의 Bullseye의 고리도 쌓을 것임을 의미합니다 (예 : 내 예에서 반경은 가장 큰 그룹의 크기 대신 63 개 그룹의 합과 같습니다). 나 ~하지 않다 그것이 대부분의 사람들이 Bullseye 음모에서, 특히 그룹이 중첩 될 때 기대하는 것이라고 생각하십시오. 사용 geom_bar(position = position_identity()) 쌓인 고리를 층계 원으로 바꿉니다.

편집 2 : 예제 ggplot2 문서 :
enter image description here

도움이 되었습니까?

해결책

전설에 숫자를 추가 할 수 있습니다.

library(ggplot2)
critters <- structure(list(Zoo = "Omaha", Animals = 50, Bears = 10, PolarBears = 3), .Names = c("Zoo", "Animals", "Bears", "PolarBears"), row.names = c(NA, -1L), class = "data.frame")
d <- data.frame(animal=factor(c(rep("Animals", critters$Animals),
       rep("Bears", critters$Bears), rep("PolarBears", critters$PolarBears)),
       levels = c("PolarBears", "Bears", "Animals"), ordered= TRUE))
levels(d$animal) <- apply(data.frame(table(d$animal)), 1, paste, collapse = ": ")
ggplot(d, aes(x = factor(1), fill = factor(animal))) +  geom_bar() +
  coord_polar() + labs(x = NULL, fill = NULL) +
  scale_fill_manual(values = c("firebrick2", "yellow2", "green3")) +
  opts(title = paste("Animals, Bears and Polar Bears:\nOmaha Zoo", sep=""))

다른 팁

플롯에 직접 추가 할 수도 있습니다.

grr <- ggplot(d, aes(x = factor(1), fill = factor(animal))) +  geom_bar() +
coord_polar() + labs(x = NULL, fill = NULL) +
scale_fill_manual(values = c("firebrick2", "yellow2", "green3")) +
opts(title = paste("Animals, Bears and Polar Bears:\nOmaha Zoo", sep=""))+
geom_text(y=c(3,10,50)-3,label=c("3","10","50"),size=4)
grr
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top