R- scatter plots

目录

  • Generic X-Y plot定义
    • 1 添加x、y标签
    • 2 添加主标题,参数main
    • 3 添加副标题,参数sub
    • 4 添加颜色,参数col
    • 5 添加xy轴显示限制,参数xlim
    • 6 图状、点状、线状
    • 7 平滑曲线
    • 8 画函数图像

Generic X-Y plot定义

plot(x, y, ...) # ?plot 请查看帮助文档

代码及结果:

#打开数据集前6行
head(cars)
R- scatter plots_第1张图片
cars数据集
plot(x,y)
plot(x = cars$speed, y = cars$dist)
R- scatter plots_第2张图片
speed为x,dist为y
plot(x = cars$dist, y = cars$speed)
#It probably makes more sense for speed to go on the x-axis since stopping distance is a function of speed #more than the other way around
R- scatter plots_第3张图片
dist为x,speed为y
1 添加x、y标签
#添加x、y标签
plot(x = cars$speed, y = cars$dist, xlab = "Speed", ylab = "Distance")
R- scatter plots_第4张图片
添加x、y标签
2 添加主标题,参数main
#添加主标题,参数main
plot(x = cars$speed, y = cars$dist,xlab = "Speed", ylab = "Stopping Distance", main = "My Plot")
R- scatter plots_第5张图片
添加主标题
3 添加副标题,参数sub
#添加副标题,参数sub
plot(cars, main = "My Plot", sub ="My Plot Subtitle")
R- scatter plots_第6张图片
添加副标题
4 添加颜色,参数col
#添加颜色,参数col
plot(cars, col = 2)
R- scatter plots_第7张图片
添加颜色
5 添加xy轴显示限制,参数xlim
#添加xy轴显示限制,参数xlim
plot(cars, xlim = c(10,15))
R- scatter plots_第8张图片
添加xy轴显示限制
6 图状、点状、线状
R- scatter plots_第9张图片
type 图形状9种

R- scatter plots_第10张图片
pch 点形状25种

R- scatter plots_第11张图片
lty 线形状6种

R- scatter plots_第12张图片
点的大小
# pch & lty &type &cex
plot(1:10,pch = c("@","$","#","&","%"), type = "b", lty = 3, cex =0.5, main = "Sarge says to Beetle...")
R- scatter plots_第13张图片
点、线、类型设置
7 平滑曲线
require(stats) # for lowess, rpois, rnorm
plot(cars)
lines(lowess(cars)) #R平滑曲线的方法之一lowess()
R- scatter plots_第14张图片
R平滑曲线
8 画函数图像
plot(sin, -pi, 2*pi) # see ?plot.function
R- scatter plots_第15张图片
sin(x), x [-pi, 2*pi]
# 泊松分布100个观测值,lambda = 5
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 5,
     main = "rpois(100, lambda = 5)")

R- scatter plots_第16张图片
泊松分布

参考文章:
coursera R programming week4

你可能感兴趣的:(R- scatter plots)