【发布时间】:2018-11-20 14:43:32
【问题描述】:
【问题讨论】:
-
一旦你把你的数据转换成正确的格式,你应该可以使用like this的东西了。
【问题讨论】:
使用泰坦尼克号数据集,这可以使用
来完成library(tidyverse)
data("Titanic")
Titanic %>%
as.data.frame() %>% # transform from a table to dataframe
gather(variable, value, -Freq) %>% # change to long format
group_by(variable, value) %>%
summarise(Freq = sum(Freq)) %>% # get the freq for each level of each variable
ggplot(aes(variable, Freq, fill = value)) +
geom_col(position = position_stack()) +
geom_text(aes(label = paste0(value, " (", Freq, ")")), vjust = 1,
position = position_stack()) +
theme(legend.position = "none")
【讨论】: