本篇介绍R语言base系统绘制散点图、条形图、直方图、箱线图、饼图,还将简单介绍点图、核密度图、折线图。
散点图:
attach(mtcars)
plot(wt, mpg,
main="Basic Scatterplot of MPG vs. Weight",
xlab="Car Weight (lbs/1000)",
ylab="Miles Per Gallon ", pch=19)
abline(lm(mpg ~ wt), col="red", lwd=2, lty=1)
lines(lowess(wt, mpg), col="blue", lwd=2, lty=2) 
 
条形图
library(vcd)
counts <- table(Arthritis$Improved, Arthritis$Treatment)
counts
par(mfrow=c(1,2))
# stacked barplot
barplot(counts, 
        main="Stacked Bar Plot",
        xlab="Treatment", ylab="Frequency", 
        col=c("red", "yellow","green"),            
        legend=rownames(counts)) 
 
# grouped barplot
     
     
     
 
  
barplot(counts, 
 
     
main="Grouped Bar Plot", 
 
     
xlab="Treatment", ylab="Frequency",
 
     
col=c("red", "yellow", "green"),
 
     
legend=rownames(counts), beside=TRUE)
par(mfrow=c(1,1))
 
直方图
 
箱线图
创建一个箱线图在 R 中的基本的语法是:
boxplot(x,data,notch,varwidth,names,main)
以下是所使用的参数的说明:
x - 是一个向量或一个公式
data - 是数据帧
notch - 是一个逻辑值。设置为TRUE画一个缺口
varwidth - 是一个逻辑值。设置为 true 时来画的宽度成正比到样本大小的方块。
names - 是将每个箱线图下被打印的组标签。
main - 用于给出曲线图的标题。
下面的脚本将创建 mpg(英里每加仑)和cyl(气缸数)之间的关系的一个箱线图
boxplot(mpg~cyl,data=mtcars,
        main="Car Milage Data", 
        xlab="Number of Cylinders", 
        ylab="Miles Per Gallon")
 
饼图
 
点图
x <- mtcars[order(mtcars$mpg),]                      
x$cyl <- factor(x$cyl)                                 
x$color[x$cyl==4] <- "red"                              
x$color[x$cyl==6] <- "blue"
x$color[x$cyl==8] <- "darkgreen" 
dotchart(x$mpg,
         labels = row.names(x),                               
         cex=.7, 
         pch=19,                                              
         groups = x$cyl,                                       
         gcolor = "black",
         color = x$color,
         main = "Gas Mileage for Car Models\ngrouped by cylinder",
         xlab = "Miles Per Gallon")
 
核密度图
 
折线图
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
t1 <- subset(Orange, Tree==1)
plot(t1$age, t1$circumference,
     xlab="Age (days)",
     ylab="Circumference (mm)",
     main="Orange Tree 1 Growth")
plot(t1$age, t1$circumference,
     xlab="Age (days)",
     ylab="Circumference (mm)",
     main="Orange Tree 1 Growth",
     type="b")
par(opar)
 
 

R语言图形base系统(三)的更多相关文章

  1. R语言图形base系统(一)

           一般R作图有三大绘图系统:base系统.ggplot2绘图系统.lattice绘图系统.        本篇主要介绍base系统绘图时的图形参数.一般用plot()函数来完成.在R中,若 ...

  2. R语言图形base系统(二)

    x<-c(1:10) y<-x z<-10/x opar<-par(no.readonly = T) par(mar=c(5,4,4,8)+0.1) plot(x,y,type ...

  3. R语言实战读书笔记(三)图形初阶

    这篇简直是白写了,写到后面发现ggplot明显更好用 3.1 使用图形 attach(mtcars)plot(wt, mpg) #x轴wt,y轴pgabline(lm(mpg ~ wt)) #画线拟合 ...

  4. R语言-图形初阶

    在本节中,主要目的是如何使用R语言做出简单的图形 案例1:做出wt和mpg之间的关系 attach(mtcars) plot(wt,mpg) abline(lm(mpg~wt)) title('Reg ...

  5. R语言高性能编程(三)

    一.使用并行计算加倍提升性能1.数据并行 VS 任务并行实现数据并行的算法scoket 并行性注意并行计算时间并不与执行任务的计算资源数目成正比(计算机核心),amdahl定律:并行代码的速度受限于串 ...

  6. R语言-图形辅助

    1.画底纹格子    grid()函数 > plot(rnorm(100)) > grid() #画底纹格子 > grid(nx=NA, ny=8, #画水平底纹,横坐标无分隔,纵坐 ...

  7. R语言学习笔记(三)

    5. 数据结构 5.1 数据结构简介 (1)向量 一个向量的所有元素必须有相同的类型(模式) (2)列表 列表可以非同质的 列表可按位置索引:lst[[2]] 抽取子列表:lst[c(2,5)] 列表 ...

  8. R语言学习笔记(三):零碎知识点(1-10)

    1--c() c表示"连接"(concatenate). 在R中向量是连续存储的,因此不能插入或删除元素. 2--seq() seq()的特殊用法,可以用在for循环里for(i ...

  9. R语言与概率统计(三) 多元统计分析(中)

    模型修正 #但是,回归分析通常很难一步到位,需要不断修正模型 ###############################6.9通过牙膏销量模型学习模型修正 toothpaste<-data. ...

随机推荐

  1. vscode - 安装离线插件

    打开网站(示例): https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow 下载扩展 vscode 安装离 ...

  2. Sql中常用的创建表 约束 主外键 增删改查的语句

    创建数据库 USE master; GO --日记数据库 create database DiaryBase on ( name=DiaryBase_Dat,--逻辑名称 FILENAME='c:\D ...

  3. C++11之右值引用(三):使用C++11编写string类以及“异常安全”的=运算符

    前面两节,说明了右值引用和它的作用.下面通过一个string类的编写,来说明右值引用的使用. 相对于C++98,主要是多了移动构造函数和移动赋值运算符. 先给出一个简要的声明: class Strin ...

  4. Python——os.path.dirname(__file__) 与 os.path.join(str,str)

    Python os.path.dirname(__file__) Python os.path.join(str,str)   (1).当"print os.path.dirname(__f ...

  5. (CF#257)A. Jzzhu and Children

    There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number al ...

  6. 【Excle数据透视表】如何将行字段中的某个项目拖动到第一行显示

    如下图:需要把上海放到第一显示 步骤 方法一: 单击"地区"下的"上海"→鼠标移动到单元格边框处→鼠标变成四向箭头→向上拖拽 方法二: 单击单元格A5→编辑区域 ...

  7. C语言 | 基础知识点笔记

    函数 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ...

  8. &&与&符号区别

    http://topic.csdn.net/u/20080915/16/f5125300-f69f-4da8-9c3a-a7458590553f.html && 与 &区别: ...

  9. nginx proxy cache配置和清理

    1.nginx需要编译Purge模块 2.nginx.conf 配置cache: proxy_cache_path  /home/cache/xxx levels=1:2  keys_zone=cac ...

  10. kernel BUG

    https://kernelnewbies.org/FAQ/BUG BUG() and BUG_ON(condition) are used as a debugging help when some ...