Kevin Santos
Kevin Santos

Reputation: 87

Plot observations with same name in different columns in r

I have the next dataframe

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

Is it possible to get a plot with a facet based on Grade, color by year and showing a different bar for every observation?

Upvotes: 0

Views: 122

Answers (1)

langtang
langtang

Reputation: 24845

You can use geom_col()

ggplot(df, aes(Domain,Score,fill=factor(Year))) + 
  geom_col(position="dodge") + facet_wrap(~Grade) + 
  labs(fill="") + theme(legend.position="bottom")

reasoning

Upvotes: 1

Related Questions