条形图不适合用于绘制随时间变化的变量
![](https://img-blog.csdnimg.cn/7d2b9af4a92d456f8172dc079e90ff7a.png)
连续型:BOD %>% ggplot(aes(Time,demand))+
geom_col()
![](https://img-blog.csdnimg.cn/42e8fed9fd8944699316e0c1928fcaf6.png)
离散型(将time转换为因子型)
BOD %>% ggplot(aes(
factor(Time),demand))+
geom_col()#离散型(将time转换为因子型)只是将time视为标签原数据中么有time=6.
![](https://img-blog.csdnimg.cn/e6b159301b32469bba8ae70fc68115a2.png)
pg_mean %>% ggplot(aes(group,weight))+
geom_col(
fill='red',
colour='green')#fill填充条形图颜色, colour为条形图添加边框线
![](https://img-blog.csdnimg.cn/833c6ca14b0f4c198c282dba3daadfa1.png)
簇状条形图
将分类变量映射到
fill参数上,运行命令
position = 'dodge'
![](https://img-blog.csdnimg.cn/07087490be064dcebaa2eab430350d93.png)
cabbage_exp %>% ggplot(aes(Date,Weight,fill=Cultivar))+
geom_col(position = 'dodge')
![](https://img-blog.csdnimg.cn/731ba1f37bec497cab7b74b22f76af14.png)
position = 'dodge'#将两组条形在水平上错开排列,否则会输出为堆积图
cabbage_exp %>% ggplot(aes(Date,Weight,fill=Cultivar))+
geom_col()
![](https://img-blog.csdnimg.cn/0176fdf5a5c544a895069963860d40da.png)
scale_fill_brewer()函数对图形颜色进行设置,RColorBrewer包中的Pastel1调色板
#??palette查看调色板
![](https://img-blog.csdnimg.cn/5951b0854afe452e8035017f43cf3853.png)
cabbage_exp %>% ggplot(aes(Date,Weight,fill=Cultivar))+
geom_col(position = 'dodge',colour='black')+