耿秀華
摘? 要:本文介紹了R中最經(jīng)常被用到的一個繪圖函數(shù)-plot()函數(shù),主要描述了如何改變plot()函數(shù)所繪圖形中圖形符號的形狀、顏色和尺寸,并舉例說明。
關(guān)鍵詞:R語言;plot()函數(shù);圖形符號
中圖分類號:TP39? ? ?文獻(xiàn)標(biāo)識碼:A? ? 文章編號:1007-9416(2018)10-0000-00
1引言
R語言擁有強大的繪圖功能,在R中經(jīng)常被用到的一個繪圖函數(shù)是plot()函數(shù),本文主要介紹如何改變plot()函數(shù)中繪圖符號的形狀、顏色和尺寸。
2 plot()函數(shù)中圖形符號形狀的設(shè)置
繪圖符號缺省情況下為空心圓,通過設(shè)置參數(shù)pch的值可以更改圖形符號的形狀。比如,當(dāng)pch=9時,圖形符號的形狀為鉆石形,默認(rèn)為pch=1, 即空心圓。
所繪圖形如圖1所示。
設(shè)pch=16(實心圓)
輸入命令
>plot(Speed,Dist,main="剎車距離與車速關(guān)系圖",xlab="車速",ylab="剎車距離",pch=16)
所繪圖形如圖2所示。
3 plot()函數(shù)中圖形符號顏色的設(shè)置
繪圖符號顏色缺省情況下為黑色,通過設(shè)置參數(shù)col的值可以更改圖形符號的顏色。比如,當(dāng)col=2時,圖形符號的顏色為紅色。
設(shè)pch=16,col=2
輸入命令
>plot(Speed,Dist,main="剎車距離與車速關(guān)系圖",xlab="車速",ylab="剎車距離",pch=16,col=2)
所繪圖形如圖3所示。
4 plot()函數(shù)中圖形符號尺寸的設(shè)置
繪圖符號顏色缺省情況下為黑色,通過設(shè)置參數(shù)col的值可以更改圖形符號的顏色。比如,當(dāng)col=2時,圖形符號的顏色為紅色。
設(shè)pch=16,col=4,cex=2
輸入命令
>plot(Speed,Dist,main=“剎車距離與車速關(guān)系圖”,xlab=“車速”,ylab=“剎車距離”,pch=16,col=2,cex=2)
所繪圖形如圖4所示。
參考文獻(xiàn)
[1] Emmanuel Paradis.R語言初學(xué)者指南[M]. Institut des Sciences de lEvolution Universit?e Montpellier II F-34095 Montpellier c?edex 2005.
[2] R Development Core Team.R語言簡介[M].2006.
[3] 張金龍.R語言初步-數(shù)據(jù)處理、繪圖與編程[R].2010.
The Symbol, color and Size of Plot() Function in R Language
GENG Xiu-hua
(School of Software and Information of Beijing Information Technical College, Beijing 100018, China)
Abstract: This paper introduces the plot() function, which is the most frequently used drawing function in R. It mainly describes how to change the shape, color and size of the graphic symbol in the plot() function, and illustrate with examples.
Keywords: R language; plot() function; graphic symbol