• 【564】用 R 制图


    参考:R语言绘图

    plot(cars$dist~cars$speed, #y~x,cars是R自带的数据
         main="Relationship between car distance & speed", #标题
         xlab = "Speed(miles per hour)", #x轴标题
         ylab = "Distance travelled (miles)", #Y轴标题
         xlim = c(0,30), #设置x轴的取值区间为0到30
         ylim = c(0,140), #设置y轴的取值区间为0到140
         xaxs = "i", #这里是设置x轴的风格,暂时没看明白有多大区别
         yaxs = "i",
         col = "red", #设置颜色
         pch = 19) #pch指代点的形状,用数字表示,可查看帮助文档
    # 如果要保存图片怎么办呢?我觉得最简单的方法就是使用RStudio这个IDE,极其得好,
    # 可惜很多人都不知道。#如果你不会,可以用如下代码实现:
    #(图形的参数还有很多个,我这里只使用了其中的几个)
    png(filename="散点图.png",width=480,height=480)
    dev.off()
    

      显示效果:

      ggplot2

    #+++++++画散点图等展示数据的图+++++++
    #install.packages("ggplot2")#如果还没安装过这个包可以安装
    library(ggplot2)
    data=data.frame(x=c(1:18),y=sin(c(1:18)/6*pi)+1.2)#数据一定要用data.frame储存
    #pdf("1.pdf",width=2,height=1.5)#保存为pdf格式
    ggplot(data,aes(x=x,y=y))+
      geom_line()+geom_point(size=3)+#点和线,可以换成其他图表类型,相关代码在网上有很多
      theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank(),panel.background=element_blank(),
            axis.line=element_line(colour="black"))+
      scale_x_continuous(expand=c(0,0))+
      scale_y_continuous(expand=c(0,0))+
      xlab("t")+ylab("Demand level")
    #dev.off()#保存为pdf格式
    

      显示效果: 

  • 相关阅读:
    win7纯净环境下搭建深度学习环境:Python+TensorFlow+jupyter
    linux安全配置-将ssh服务隐藏于Internet(端口碰撞)
    S3C2440小板子-烧写笔记
    SecureCRT使用技巧
    Linux 下设置静态IP
    win7设置虚拟网卡以及如何设置静态IP
    第八章学习小结
    第七章学习小结
    第六章学习小结
    第五章学习小结
  • 原文地址:https://www.cnblogs.com/alex-bn-lee/p/14809679.html
Copyright © 2020-2023  润新知