耿秀華



摘? 要:本文介紹了R中最經(jīng)常被用到的一個(gè)繪圖函數(shù)-plot()函數(shù),主要描述了如何改變plot()函數(shù)所繪圖形中圖形符號(hào)的形狀、顏色和尺寸,并舉例說(shuō)明。
關(guān)鍵詞:R語(yǔ)言;plot()函數(shù);圖形符號(hào)
中圖分類號(hào):TP39? ? ?文獻(xiàn)標(biāo)識(shí)碼:A? ? 文章編號(hào):1007-9416(2018)10-0000-00
1引言
R語(yǔ)言擁有強(qiáng)大的繪圖功能,在R中經(jīng)常被用到的一個(gè)繪圖函數(shù)是plot()函數(shù),本文主要介紹如何改變plot()函數(shù)中繪圖符號(hào)的形狀、顏色和尺寸。
2 plot()函數(shù)中圖形符號(hào)形狀的設(shè)置
繪圖符號(hào)缺省情況下為空心圓,通過(guò)設(shè)置參數(shù)pch的值可以更改圖形符號(hào)的形狀。比如,當(dāng)pch=9時(shí),圖形符號(hào)的形狀為鉆石形,默認(rèn)為pch=1, 即空心圓。
所繪圖形如圖1所示。
設(shè)pch=16(實(shí)心圓)
輸入命令
>plot(Speed,Dist,main="剎車距離與車速關(guān)系圖",xlab="車速",ylab="剎車距離",pch=16)
所繪圖形如圖2所示。
3 plot()函數(shù)中圖形符號(hào)顏色的設(shè)置
繪圖符號(hào)顏色缺省情況下為黑色,通過(guò)設(shè)置參數(shù)col的值可以更改圖形符號(hào)的顏色。比如,當(dāng)col=2時(shí),圖形符號(hào)的顏色為紅色。
設(shè)pch=16,col=2
輸入命令
>plot(Speed,Dist,main="剎車距離與車速關(guān)系圖",xlab="車速",ylab="剎車距離",pch=16,col=2)
所繪圖形如圖3所示。
4 plot()函數(shù)中圖形符號(hào)尺寸的設(shè)置
繪圖符號(hào)顏色缺省情況下為黑色,通過(guò)設(shè)置參數(shù)col的值可以更改圖形符號(hào)的顏色。比如,當(dāng)col=2時(shí),圖形符號(hào)的顏色為紅色。
設(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語(yǔ)言初學(xué)者指南[M]. Institut des Sciences de lEvolution Universit?e Montpellier II F-34095 Montpellier c?edex 2005.
[2] R Development Core Team.R語(yǔ)言簡(jiǎn)介[M].2006.
[3] 張金龍.R語(yǔ)言初步-數(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