막대 위에 텍스트 항목을 자동으로 인쇄하는 방법에 대한 수많은 스레드를 보았습니다. 그러나 이것이 작동하지 않는 이유를 알 수 없습니다.
나는 가지고있다
와
p %>%
as_tibble() %>%
mutate(nystudie=as.character(nystudie),
n.stage=as.factor(n.stage)) %>%
bind_rows(., mutate(., nystudie="all")) %>%
count(nystudie, n.stage)
같이
# A tibble: 13 x 3
nystudie n.stage n
<chr> <fct> <int>
1 A 0 4
2 A 2 4
3 A 3 1
4 all 0 22
내가 좋아하는 것 n
, 각 위의 텍스트로 인쇄 할 n.stage
당 nystudie
.
그래서 이것은 막대 그래프를 제공합니다
ggplot(aes(nystudie, n, color = n.stage, fill= n.stage, label=n)) +
geom_col(position = position_dodge2(preserve = "single", padding = 0.1))
하지만 추가
+ geom_text(vjust=0)
오류가 발생합니다.
매핑은 aes ()로 만들어야합니다.
그 이유는 무엇이며 어떻게 geom_text
인쇄 할 수 aes(label=n)
있습니까?
p <- structure(list(nystudie = c("B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "A", "A", "B", "B", "B", "B", "B", "B",
"B", "B", "A", "B", "B", "A", "B", "A", "A", "A", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B"), n.stage = structure(c(3L, 5L, 1L, 1L, 1L,
1L, 5L, 4L, 3L, 2L, 3L, 4L, 1L, 3L, 3L, 1L, 3L, 1L, 2L, 2L, 1L,
4L, 2L, 1L, 2L, 4L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 4L, 1L, 2L, 1L,
4L, 4L, 1L, 1L, 5L, 1L, 1L, 2L, 4L, 1L, 4L, 1L, 2L), .Label = c("0",
"1", "2", "3", "4"), class = "factor")), row.names = c(NA, -50L
), class = "data.frame")
아마도 당신은 이것을 찾고 있습니다 :
library(tidyverse)
#Data and plot
p %>%
as_tibble() %>%
mutate(nystudie=as.character(nystudie),
n.stage=as.factor(n.stage)) %>%
bind_rows(., mutate(., nystudie="all")) %>%
count(nystudie, n.stage) %>%
ggplot(aes(nystudie, n, color = n.stage, fill= n.stage, label=n)) +
geom_col(position = position_dodge2(preserve = "single", padding = 0.1))+
geom_text(aes(label=n),position = position_dodge2(0.9),vjust=-0.5)
산출:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다