R語言低級繪圖函數-points


points 用來在一張圖表上添加點,指定好對應的x和y坐標,就可以添加不同形狀,顏色的點了;

基本用法:

通過x和y設置點的坐標

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
points(x = c(3, 3), y = c(3, 5))

效果圖如下:

參數設置:

cex : 設置點的大小

代碼示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
points(x = c(3, 3), y = c(3, 5), cex = c(2, 4))

效果圖如下:

lwd : 設置點的邊框的寬度

代碼示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
points(x = c(3, 3), y = c(3, 5), cex = 4, lwd = c(2, 4))

效果圖如下:

pch : 設置點的形狀,取值范圍為1到25,

代碼示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
index <- 1:25
start <- 0
for (i in 1:5) {
for (j in 1:5) {
start <- start + 1
points(x = i, y = j, pch = index[start], cex = 1.5)
text(x = i, y = j, labels = index[start], pos = 3, offset = 1)
}
}

效果圖如下:

col:  設置點的邊框的顏色

代碼示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
index <- 1:25
start <- 0
for (i in 1:5) {
	for (j in 1:5) {
		start <- start + 1
		points(x = i, y = j, pch  = index[start], cex = 1.5, col = "red")
		text(x = i, y = j, labels = index[start], pos = 3, offset = 1)
	}
}

效果圖:

 

 bg : 設置點的背景色,其實就是填充色,需要注意的是,只有形狀為21到25的點是有填充色的

代碼示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
index <- 1:25
start <- 0
for (i in 1:5) {
	for (j in 1:5) {
		start <- start + 1
		points(x = i, y = j, pch  = index[start], cex = 1.5, bg = "red")
		text(x = i, y = j, labels = index[start], pos = 3, offset = 1)
	}
}

效果圖如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM