ใส่ชาร์ปเพื่อให้เป็นหัวข้อ การดึงข้อมูล sample_hoiseprice.csv เข้ามาในโปรแกรม R
df = read.csv("sample_houseprice.csv")
head(df)
## Id MSSubClass MSZoning LotFrontage LotArea Street YearBuilt SalePrice
## 1 12 60 RL 85 11924 Pave 2005 345000
## 2 14 20 RL 91 10652 Pave 2006 279500
## 3 21 60 RL 101 14215 Pave 2005 325300
## 4 26 20 RL 110 14230 Pave 2007 256300
## 5 28 20 RL 98 11478 Pave 2007 306000
## 6 33 20 RL 85 11049 Pave 2007 179900
attach(df)
plot(LotFrontage,SalePrice)
สามารถดูสีจากในอินเตอร์เน็ตได้เลย จะใส่เป็นโค้ดสีหรือเป็นชื่อสีก็ได้
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"))
ขยายจุดในกราฟให้ใหญ่ขึ้นโดยใช้คำสั่ง cex
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"), cex = 1.5)
ถ้าอยากทำให้กราฟดูน่ารักขึ้น เราสามารถเปลี่ยนลักษณะ symbols ของกราฟได้โดยใช้คำสั่ง pch
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"), cex = 1.5, pch = 8)
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"), cex = 1.5, pch = 8, cex.lab = 1.5)
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"), cex = 1.5, pch = 8, cex.lab = 1.5, xlab = "Lot Frontage", ylab = "Sale Price")
ใช้คำสั่ง cex.axis
plot(LotFrontage,SalePrice , col = c("pink", "lightblue"), cex = 1.5, pch = 8, cex.lab = 1.5, xlab = "Lot Frontage", ylab = "Sale Price", cex.axis = 1.2)
หรือถ้ากราฟแบบนี้ดูยากไป อยากได้เป็นกราฟแท่งเปลี่ยนจาก plot เป็น barplot แต่การจะสร้างได้ต้องเริ่มจากการสร้างตารางแจกแจงความถี่ก่อน
table(MSZoning,MSSubClass)
## MSSubClass
## MSZoning 20 60 80 120 160 180
## FV 12 17 0 3 8 0
## RL 95 52 2 28 0 0
## RM 0 0 0 2 0 3
barplot(table(MSZoning,MSSubClass), col = c("lightblue","pink", "darkseagreen"))
barplot(table(MSZoning,MSSubClass), col = c("lightblue","pink","darkseagreen"), beside = TRUE)
barplot(table(MSZoning,MSSubClass), col = c("lightblue","pink","darkseagreen"), beside = TRUE, legend.text = TRUE)
mfrow = c(num of row, num of col)
par(mfrow = c(1,2))
plot(LotFrontage,SalePrice, col = c("pink","lightblue"), cex = 1.5)
plot(LotArea,SalePrice, col = c("pink","lightblue"), cex = 1.5)
par(mfrow = c(1,2))
boxplot(LotFrontage,SalePrice, col = c("pink","lightblue"), cex = 1.5)
boxplot(LotArea,SalePrice, col = c("pink","lightblue"), cex = 1.5)
par(mfrow = c(1,2))
boxplot(LotFrontage,SalePrice, col = c("pink","lightblue"), cex = 1.5,horizontal = TRUE)
boxplot(LotArea,SalePrice, col = c("pink","lightblue"), cex = 1.5,horizontal = TRUE)