本篇介绍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)
 
 

最新文章

  1. PHP服务器配置环境变量
  2. 转-servlet 获取 post body 体用流读取为空的问题
  3. web项目 验证码 *** 最爱那水货
  4. Swift 关键字汇总
  5. js-数据类型
  6. 非对称认证方式 可以用在 asp.net webapi 的安全机制里面
  7. uboot在s3c2440上的移植(1)
  8. Android核心基础(手机卫士的一个知识点总结)
  9. JQ 无刷新评论
  10. awk程序设计语言之-awk基础
  11. MiniProfiler工具介绍
  12. Json对象和Json字符串之间的转换
  13. 一天搞定CSS:盒模型content、padding、border、margin--06
  14. docker搭建zabbix
  15. Oozie调用Spark实例
  16. 从0开始的Python学习008变量
  17. Lock和Synchronized
  18. unity室内外VR漫游
  19. C#中用DateTime的ParseExact方法解析日期时间(excel中使用系统默认的日期格式)
  20. spring的工厂类

热门文章

  1. MonoBehaviour.FixedUpdate 固定更新
  2. Laravel之认证服务
  3. Recycling Settings for an Application Pool &lt;recycling&gt;
  4. Nginx:HTTP过滤模块
  5. WebService学习小结
  6. linux标准输入输出错误输出
  7. PHP和Java的主要区别有哪些?哪个最适合Web开发语言?
  8. c#创建对象并动态添加属性
  9. 【已解决】ckfinder_php_3.4.4 IIS 报错 无效请求
  10. oracle中过滤中文字符或者汉字的函数