在R語言中,可以使用par()
函數來將兩個圖畫在一起。以下是一個示例:
# 創建第一個圖形
plot(1:10, 1:10, type = "l", col = "blue", xlab = "x", ylab = "y", main = "Plot 1")
# 創建第二個圖形
plot(1:10, 10:1, type = "l", col = "red", xlab = "x", ylab = "y", main = "Plot 2")
# 將兩個圖形放在一起
par(mfrow = c(1, 2))
plot(1:10, 1:10, type = "l", col = "blue", xlab = "x", ylab = "y", main = "Plot 1")
plot(1:10, 10:1, type = "l", col = "red", xlab = "x", ylab = "y", main = "Plot 2")
在這個示例中,我們首先創建了兩個單獨的圖形,然后使用par(mfrow = c(1, 2))
將兩個圖形放在一起。mfrow
參數設置了繪圖區域的排列方式,這里將其設置為一行兩列,即將兩個圖形放在同一行的兩個列中。
注意,在使用par()
函數之前,要先創建好要放在一起的圖形。