1. 使用polygon進行純色填充
# polygon函數介紹
polygon(x, y = NULL, density = NULL, angle = 45,
border = NULL, col = NA, lty = par("lty"),
..., fillOddEven = FALSE)
其中density爲填充的陰影線的密度,angle爲陰影線的斜率(角度)。值得注意的是,當你需要純色填充時,density和angle可以忽略不寫。然後border爲邊框的顏色。同時border也可以是邏輯。即FALSE相當於NULL,TRUE相當於爲前景色。
# Distance Between Brownian Motions 布朗運動之間的距離
n <- 100
xx <- c(0:n, n:0) #生成202個元素的向量,其中前面101與後面101數字對稱
yy <- c(c(0, cumsum(stats::rnorm(n))), rev(c(0, cumsum(stats::rnorm(n)))))
plot (xx, yy, type = "n", xlab = "Time", ylab = "Distance")
polygon(xx, yy, col = "gray", border = "red")
title("布朗運動之間的距離")
2. 使用polygon進行陰影線填充
# Line-shaded polygons 線陰影多邊形
plot(c(1, 9), 1:2, type = "n")
polygon(1:9, c(2,1,2,1,NA,2,1,2,1),
density = c(10, 20), angle = c(-45, 45)) #density的值爲兩個,即不同的密度
——Written in BTBU