zoukankan      html  css  js  c++  java
  • 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放到统计层的好处是可以在加一个统计层,单独存放不同的信息
    

  • 相关阅读:
    oracle对中文的排序
    sql语句分页
    一些简单的PGSQL 操作
    angularJSngSelect
    angular+ionic返回上一页并刷新
    C语言博客作业02循环结构
    c语言第一次作业顺序、分支结构
    C语言博客作业03函数
    C语言博客作业02循环结构
    第零次作业
  • 原文地址:https://www.cnblogs.com/sanmenyi/p/7205240.html
Copyright © 2011-2022 走看看