在 r 的不同列中绘制具有相同名称的观察值
Plot observations with same name in different columns in r
我有下一个数据框
df1
Domain Grade Year Score
Reasoning First 2021 0.4
Reasoning Second 2021 0.5
Reasoning First 2022 0.2
Reasoning Second 2022 0.3
Knowing First 2021 0.2
Knowing Second 2021 0.8
Knowing First 2022 0.6
Knowing Second 2022 0.5
是否有可能得到一个基于年级、颜色的分面图,并为每次观察显示不同的条形图?
您可以使用geom_col()
ggplot(df, aes(Domain,Score,fill=factor(Year))) +
geom_col(position="dodge") + facet_wrap(~Grade) +
labs(fill="") + theme(legend.position="bottom")
我有下一个数据框
df1
Domain Grade Year Score
Reasoning First 2021 0.4
Reasoning Second 2021 0.5
Reasoning First 2022 0.2
Reasoning Second 2022 0.3
Knowing First 2021 0.2
Knowing Second 2021 0.8
Knowing First 2022 0.6
Knowing Second 2022 0.5
是否有可能得到一个基于年级、颜色的分面图,并为每次观察显示不同的条形图?
您可以使用geom_col()
ggplot(df, aes(Domain,Score,fill=factor(Year))) +
geom_col(position="dodge") + facet_wrap(~Grade) +
labs(fill="") + theme(legend.position="bottom")