碎碎念一下
昨天看到別人發(fā)的威信文章也有寫這個學(xué)習(xí)筆記的,寫到第3章就沒有再更新了,一年了。
好吧,我會看完這本書的(后面幾章可能夠嗆,嘻嘻)
補充練習(xí)
rm(list = ls())
x <- rnorm(100)
hist(x)#創(chuàng)建直方圖
#為airquality數(shù)據(jù)中的每一個月,創(chuàng)建一個Wind和Ozone的關(guān)系圖
#確保所有圖在相同的軸,包含標題。
head(airquality)
par(mfrow = c(1,5))
# plot_list = list()
# for (M in unique(airquality$Month)) {
# b <- airquality[airquality$Month == M,]
# p = plot(b[,"Wind"],b[,"Ozone"],main = "Month")
# i = M-4
# plot_list[[i]] = p
# }
dev.off()
for (M in unique(airquality$Month)) {
b <- airquality[airquality$Month == M,]
a <- paste("M",M,sep = "")
assign(a,b)
}
plot(M9$Wind,M9$Ozone,main = "9")
plot(M5$Wind,M5$Ozone,main = "5")
plot(M6$Wind,M6$Ozone,main = "6")
plot(M7$Wind,M7$Ozone,main = "7")
plot(M8$Wind,M8$Ozone,main = "8")
#創(chuàng)建成為PDF文檔
dev.off()
pdf("myGrafic.pdf")
par(mfrow = c(1,1))
plot(M9$Wind,M9$Ozone,main = "9")
plot(M5$Wind,M5$Ozone,main = "5")
plot(M6$Wind,M6$Ozone,main = "6")
plot(M7$Wind,M7$Ozone,main = "7")
plot(M8$Wind,M8$Ozone,main = "8")
dev.off()
#創(chuàng)造單頁PNG文件,內(nèi)含練習(xí)2的5個圖形,確定一個合適的布局顯示數(shù)據(jù)
png("myPng.png")
a = rbind(c(1,3),c(1,4),c(2,5))
layout(a)#a這里注意一定要是矩陣
plot(M9$Wind,M9$Ozone,main = "9")
plot(M5$Wind,M5$Ozone,main = "5")
plot(M6$Wind,M6$Ozone,main = "6")
plot(M7$Wind,M7$Ozone,main = "7")
plot(M8$Wind,M8$Ozone,main = "8")
dev.off()
#每月單獨一行,顏色不同,添加圖例
a = matrix(c(1,2,3,4,5))
par(mfrow = c(5,2))
layout(a)#a這里注意一定要是矩陣
plot(M9$Wind,M9$Ozone,main = "9",col = "blue")#如果報錯說不夠?qū)挘桶旬媹D區(qū)域拉寬就好了
legend("topright",legend = "wind",pch = 16,"red")
plot(M5$Wind,M5$Ozone,main = "5",col = "red")
legend("topright",legend = "wind",pch = 16,"red")
plot(M6$Wind,M6$Ozone,main = "6",col = "yellow")
legend("topright",legend = "wind",pch = 16,"red")
plot(M7$Wind,M7$Ozone,main = "7",col = "violetred")
legend("topright",legend = "wind",pch = 16,"red")
plot(M8$Wind,M8$Ozone,main = "8",col = "turquoise1")
legend("topright",legend = "wind",pch = 16,"red")
dev.off()
graphics.off()