Home > Software engineering >  Plot observations with same name in different columns in r
Plot observations with same name in different columns in r

Time:05-19

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?

CodePudding user response:

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

  • Related