先写一些需要用到的知识点,比如包、函数
dplyr 很好用的包 经常与ggplot2连用
mutate:用于对数据框的列进行重新处理,或者用处理的结果添加新列
数据清洗:
1、na.omit() #去除数组当中的空值
newdata
ggplot:
1、在ggplot的里面添加直线:
geom_hline()添加水平线
geom_viline()添加垂直线 #geom_hline(yintercept=1.3,type=4)+geom_vline(xintercept=-1.1,type=4) #type=4是虚线
增加斜线:
geom_abline(slope=1,intercept=0,color='red',size=2) #增加一个y=1*x+0的直线
slope设置斜率,intercept设置截距,color设置线条颜色,size设置线条粗细
2、ggplot - - >labs
title:设置主标题
subtitle:设置子标题(在主标题下面)
caption:设置副标题(在右下角)
color:设置颜色图例的标题
设置图片的标题(title), 子标题(subtitle), 引用(caption)
代码示例:
ggplot(mtcars, aes(mpg, wt, colour = cyl)) +