나는 관련 질문을 겪었고 그 대답은 geom_col
막대 와 일치하지 않는 레이블 문제를 해결하지 못합니다 .
데이터
x <- structure(
list(capacity = c(0, 0, 0, 2.1, 3.1, 4, 4.6, 5.6, 6,
1.9, 2.3, 3.8),
year = c("FY21", "FY21", "FY21", "FY21", "FY21",
"FY20", "FY20", "FY20", "FY20", "FY19", "FY19", "FY19"),
unified_date = structure(c(18536, 18567, 18597, 18628, 18659,
18567, 18597, 18628, 18659, 18536,
18567, 18597), class = "Date")),
row.names = c(NA, -12L), class = c("tbl_df", "tbl", "data.frame"))
암호
ggplot2::ggplot(x, aes(x = unified_date, y = capacity, fill = year)) +
geom_col(position = "dodge") +
geom_text(aes(label = capacity),
position = position_dodge(width = 1),
vjust = -0.5, size = 4)
차트
나는 추가 해봤 fill = year
받는 사람 geom_text
aes
, 또는 group = year
이동, aes
주변 값에 변형 position_dodge()
아무것도 -.
이 시도:
#Code
ggplot2::ggplot(x, aes(x = factor(unified_date), y = capacity, fill = year)) +
geom_bar(stat='identity',position = "dodge") +
geom_text(aes(label = capacity),
position=position_dodge(width=0.9), size = 4,vjust=-0.5)+
xlab('Date')
산출:
그리고 한 달 동안 제대로 작업하려면 다음을 시도하십시오.
#Code 2
x %>% mutate(Month=format(unified_date,'%b')) %>%
mutate(Month=factor(Month,levels = unique(Month),ordered = T)) %>%
ggplot2::ggplot(aes(x = Month, y = capacity, fill = year)) +
geom_bar(stat='identity',position = "dodge") +
geom_text(aes(label = capacity),
position=position_dodge(width=0.9), size = 4,vjust=-0.5)+
xlab('Date')
산출:
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다