目錄
- Generic X-Y plot定義
- 1 添加x、y標簽
- 2 添加主標題枫吧,參數(shù)main
- 3 添加副標題宴倍,參數(shù)sub
- 4 添加顏色,參數(shù)col
- 5 添加xy軸顯示限制检疫,參數(shù)xlim
- 6 圖狀讶请、點狀、線狀
- 7 平滑曲線
- 8 畫函數(shù)圖像
Generic X-Y plot定義
plot(x, y, ...) # ?plot 請查看幫助文檔
代碼及結(jié)果:
#打開數(shù)據(jù)集前6行
head(cars)
cars數(shù)據(jù)集
plot(x,y)
plot(x = cars$speed, y = cars$dist)
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
dist為x,speed為y
1 添加x屎媳、y標簽
#添加x夺溢、y標簽
plot(x = cars$speed, y = cars$dist, xlab = "Speed", ylab = "Distance")
添加x、y標簽
2 添加主標題烛谊,參數(shù)main
#添加主標題风响,參數(shù)main
plot(x = cars$speed, y = cars$dist,xlab = "Speed", ylab = "Stopping Distance", main = "My Plot")
添加主標題
3 添加副標題,參數(shù)sub
#添加副標題丹禀,參數(shù)sub
plot(cars, main = "My Plot", sub ="My Plot Subtitle")
添加副標題
4 添加顏色状勤,參數(shù)col
#添加顏色,參數(shù)col
plot(cars, col = 2)
添加顏色
5 添加xy軸顯示限制湃崩,參數(shù)xlim
#添加xy軸顯示限制荧降,參數(shù)xlim
plot(cars, xlim = c(10,15))
添加xy軸顯示限制
6 圖狀、點狀攒读、線狀
type 圖形狀9種
pch 點形狀25種
lty 線形狀6種
點的大小
# pch & lty &type &cex
plot(1:10,pch = c("@","$","#","&","%"), type = "b", lty = 3, cex =0.5, main = "Sarge says to Beetle...")
點朵诫、線、類型設(shè)置
7 平滑曲線
require(stats) # for lowess, rpois, rnorm
plot(cars)
lines(lowess(cars)) #R平滑曲線的方法之一lowess()
R平滑曲線
8 畫函數(shù)圖像
plot(sin, -pi, 2*pi) # see ?plot.function
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)")
泊松分布
參考文章:
coursera R programming week4