[英]How to `table` all factors columns and ggplot geom_bar with facet_wrap?
我们将列gather
为“长”格式,然后执行ggplot
library(tidyverse)
df %>%
# gather to long format
gather(na.rm = TRUE) %>%
# get the frequency count of key, value columns
count(key, value) %>%
ggplot(., aes(x = value, y = n)) +
geom_bar(stat = "identity") +
# facet wrap with key column
facet_wrap(~ key)
试试这个
library(tidyverse)
df %>%
map(function(x){as.data.frame(table(x))}) %>%
bind_rows(.id = "variable") %>%
ggplot(aes(x = x, y = Freq)) +
geom_col() +
facet_wrap(~variable)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.