带组和子组的条形图

Barplot with groups and subgroups

我需要使用以下数据制作包含组和变量的箱线图:

df<-as.data.frame(cbind(c(1,2,3),
                        c(0.4,-0.11,-0.07),
                        c(0.31,0.07,0),
                        c(0.45,-0.23,0.02)))
names(df)<-c('cat','var1','var2','var3')

我需要制作一个横坐标为 cat1、纵坐标为每个变量的测量值的条形图。

例如关于cat=1,我需要在横坐标中有cat1的数量和3个条形图代表值(var1,..var3).

library(tidyverse)
df <- df %>% 
     gather(var, val, -cat)

ggplot(df, aes(cat, val, fill=var)) + 
    geom_col(position="dodge")