R语言可视化

您所在的位置:网站首页 ggplot函数在哪个包中 R语言可视化

R语言可视化

2023-04-19 19:25| 来源: 网络整理| 查看: 265

上一篇说了qplot函数,现在说一下ggplot函数 本身不能实现,需要添加层才可以。ggplot2的核心函数

library(ggplot2) ggplot(airquality,aes(Wind,Temp)) + geom_point(col="steelblue",alpha=0.4,size=5) #做散点图,半透明蓝色大小为5.使用了两层。

ggplot(airquality,aes(Wind,Temp)) + geom_point(aes(color=factor(Month)),alpha=0.4,size=5) #每个月份对应一个颜色,数据对应到颜色上面,需要加上aes函数

ggplot(airquality,aes(Wind,Temp)) + geom_point() + geom_smooth() #画出点,以及回归线

ggplot(airquality,aes(Wind,Temp)) + stat_smooth(method = "lm",se=FALSE,aes(col=Month)) #其中第二层点层和统计层不用都出现,对统计层进行添加,取消置信区间,每个月份对应不同的颜色。也可以将颜色信息放入数据层中。

ggplot(airquality,aes(Wind,Temp, col=factor(Month),group=1)) + geom_point() + stat_smooth(method = "lm",se=FALSE) #颜色对散点依旧适用,group保证对所有数据进行拟合。

ggplot(airquality,aes(Wind,Temp, col=factor(Month))) + geom_point()+ stat_smooth(method = "lm",se=FALSE)+ stat_smooth(method = "lm",se=FALSE,aes(group=1)) #将group=1放到统计层的好处是可以在加一个统计层,单独存放不同的信息



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3