다음 데이터 세트가 있습니다.
data <- structure(list(Q14 = c("< 5 people", "> 11 people", "6-10 people",
NA), count = c(148L, 13L, 34L, 21L), var = c("Team Size", "Team Size",
"Team Size", "Team Size")), row.names = c(NA, -4L), class = c("tbl_df",
"tbl", "data.frame"))
그리고 다음과 같이 geom_bar를 플로팅합니다.
library(ggplot2)
library(wesanderson)
ggplot(data) +
geom_bar( aes(x = var, y = count, fill = Q14), stat = "identity", position = "fill") +
coord_flip() +
theme(legend.position = "none",
axis.title.x=element_blank(), axis.title.y=element_blank()) +
scale_fill_manual(values = wes_palette("Zissou1", 3, type = "continuous"))
다음과 같이 바 안에 라벨을 인쇄하고 싶습니다. 참고 : 내 편집 기술이 좋지 않습니다. 물론 레이블을 정렬하고 CCW로도 회전 할 수 있습니다.
또 다른 옵션은 다음과 같은 것을 얻는 것입니다.
한 가지 옵션은 다음을 사용하는 것입니다 geom_text
.
ggplot(data, aes(x = var, y = count, fill = Q14, label = Q14)) +
geom_bar(stat = "identity", position = "fill", ) +
geom_text(position = position_fill(vjust = 0.5), size = 3) +
coord_flip() +
theme(legend.position = "none",
axis.title.x=element_blank(),
axis.title.y=element_blank()) +
scale_fill_manual(values = wes_palette("Zissou1", 3, type = "continuous"))
또 다른 옵션은 다음에서 사용하는 것 geom_label_repel
입니다 ggrepel
.
library(ggrepel)
ggplot(data, aes(x = var, y = count, fill = Q14, label = Q14)) +
geom_bar(stat = "identity", position = "fill", ) +
geom_label_repel(position = position_fill(vjust = 0.5),
direction = "y",
point.padding = 1,
segment.size = 0.2,
size = 3,
seed = 3) +
coord_flip() +
theme(legend.position = "none",
axis.title.x=element_blank(),
axis.title.y=element_blank()) +
scale_fill_manual(values = wes_palette("Zissou1", 3, type = "continuous"))
점을 유의 seed
매개 변수는 각 레이블이 이동하는 방향의 임의의 과정을 설정합니다. 내가하는 것과 같은 것이 마음에 들지 않으면 다른 번호를 선택하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다