R分组条形图
我希望有人能把这个noob指向正确的方向,尝试创建一些分组的条形图 我的数据(调查回答1=是)如下所示R分组条形图,r,ggplot2,R,Ggplot2,我希望有人能把这个noob指向正确的方向,尝试创建一些分组的条形图 我的数据(调查回答1=是)如下所示 fac_blister8 fac_lackaccess8 fac_remote8 fac_timely8 fac_none8 <dbl> <dbl> <dbl> <dbl> <dbl> 1 0 0
fac_blister8 fac_lackaccess8 fac_remote8 fac_timely8 fac_none8
<dbl> <dbl> <dbl> <dbl> <dbl>
1 0 0 0 0 1
2 0 0 0 0 1
3 0 0 0 0 1
4 0 0 0 1 0
5 0 1 1 1 0
6 0 0 0 0 1
7 0 1 0 1 0
8 0 0 0 0 1
q8 <-
q8vars %>%
group_by(fac_lackaccess8) %>%
summarise(name = n()) %>%
mutate(fac_lackaccess8 = ifelse(fac_lackaccess8 == 0,"No","Yes"))
q8_2 <-ggplot(q8, aes(x=fac_lackaccess8, y=name)) +
geom_bar(stat="identity", width = 0.5, color="green", fill="green") +
scale_y_continuous(limits = c(0,22))
q8_2 +
ylab("Count") + xlab("Working remotely and lack of resources")
fac_bull 8 fac_lackaccess 8 fac_remote 8 fac_timely 8 fac_none 8
1 0 0 0 0 1
2 0 0 0 0 1
3 0 0 0 0 1
4 0 0 0 1 0
5 0 1 1 1 0
6 0 0 0 0 1
7 0 1 0 1 0
8 0 0 0 0 1
我设法为每一列创建了一个这样的绘图
fac_blister8 fac_lackaccess8 fac_remote8 fac_timely8 fac_none8
<dbl> <dbl> <dbl> <dbl> <dbl>
1 0 0 0 0 1
2 0 0 0 0 1
3 0 0 0 0 1
4 0 0 0 1 0
5 0 1 1 1 0
6 0 0 0 0 1
7 0 1 0 1 0
8 0 0 0 0 1
q8 <-
q8vars %>%
group_by(fac_lackaccess8) %>%
summarise(name = n()) %>%
mutate(fac_lackaccess8 = ifelse(fac_lackaccess8 == 0,"No","Yes"))
q8_2 <-ggplot(q8, aes(x=fac_lackaccess8, y=name)) +
geom_bar(stat="identity", width = 0.5, color="green", fill="green") +
scale_y_continuous(limits = c(0,22))
q8_2 +
ylab("Count") + xlab("Working remotely and lack of resources")
q8%
分组依据(fac_lackaccess8)%>%
摘要(name=n())%>%
突变(fac_lackaccess8=ifelse(fac_lackaccess8==0,“否”,“是”))
问题8_2将数据重新格式化为长格式,计算每列中出现的是/否,并用facet_wrap
绘制数据:
library(tidyverse)
q8vars %>%
pivot_longer(cols = everything()) %>%
count(name, value) %>%
mutate(value = ifelse(value == 0, 'no', 'yes')) %>%
ggplot(aes(x=value, y=n)) +
geom_bar(stat="identity", width = 0.5, color="green", fill="green") +
facet_wrap(~name) +
ylab("Count") + xlab("Working remotely and lack of resources")
哦,非常感谢!我一直在为此奋斗。你是个明星!