首页 > 解决方案 > 将数据框绘制为分组条形图

问题描述

如何最好地将此数据集绘制为分组条形图,如下所示?

样本图

Zone       Oct      Nov        Dec
   1  554370.8 687899.0  702890.80
   2 1072629.8 899767.6 1058627.17
   3  660052.9 689939.9  543796.50
   4  104881.2 114328.2   86620.23

标签: rggplot2

解决方案


首先收集数据,然后用 绘制ggplot2。假设您的原始数据被称为df

library(tidyverse)
df1 <- gather(df, Month, val, -Zone)

ggplot(df1, aes(x=Zone, y=val, fill = Month)) + 
geom_bar(stat="identity", position=position_dodge())

在此处输入图像描述


推荐阅读