您好,欢迎来到叨叨游戏网。
搜索
您的当前位置:首页R语言可视化--ggplot函数

R语言可视化--ggplot函数

来源:叨叨游戏网

上一篇说了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放到统计层的好处是可以在加一个统计层,单独存放不同的信息

转载于:https://www.cnblogs.com/sanmenyi/p/7205240.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.net 版权所有 湘ICP备2024080961号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务