散点图的绘制
2019-01-29 本文已影响14人
lizg
1.R提供的数据集:Puromycin
dim(Puromycin)#查看数据集的维度
[1] 23 3
Puromycin数据集含有23行3列的数据。
head(Puromycin)#查看数据的前10行
conc rate state
1 0.02 76 treated
2 0.02 47 treated
3 0.06 97 treated
4 0.06 107 treated
5 0.11 123 treated
6 0.11 139 treated
截取符合条件的子集
part1 <- subset(Puromycin,state.name=="treated")
part1
conc rate state
1 0.02 76 treated
2 0.02 47 treated
3 0.06 97 treated
4 0.06 107 treated
5 0.11 123 treated
6 0.11 139 treated
7 0.22 159 treated
8 0.22 152 treated
9 0.56 191 treated
10 0.56 201 treated
11 1.10 207 treated
12 1.10 200 treated
画以conc为x轴,rate为y的散点图
with(part1,plot(conc,rate))
Rplot01.png
改变点的大小
cex颜色col,横纵坐标的标题xlab/ylab,主题标题title()
with(part1,plot(conc,rate,col="orange",cex=1.5,xlab = "Concentration",ylag="Rate",cex.lab=1))
title(main="Puromycin",cex.main=2)
Rplot.png
连接数据点
1.求各个变量下的平均值
install.packages("doBy")
library("doBy")
part1_mean<- summaryBy(rate ~ conc,data=part1,FUN=mean)
part1_mean
conc rate.mean
1 0.02 61.5
2 0.06 102.0
3 0.11 131.0
4 0.22 155.5
5 0.56 196.0
6 1.10 203.5
2.将平均值的点画到散点图上
with(part1,plot(conc,rate),pch=16)
points(rate.mean ~ conc,data=part1_mean,col='cyan',pch='x')
lines(rate.mean ~conc,data=part1_mean,col="blue")
Rplot02.png