問題描述
如何在多個圖中選擇一個要編輯的圖? (How to select one plot to be edit in multiple plots?)
我試圖在一張圖片中繪製兩個圖並編輯兩個圖的 x 和 y 軸。但我只能編輯右邊的情節。我無法編輯左側的情節。命令如下:
#divide ploting area in one row and two columns:
par(mfrow=c(1,2))
#plot the two graphics already with the same y limits:
plot(Age[Gender=="male"], Height[Gender=="male"], las = 1, main = "Age x Height for Males", xlab = "Age", ylab = "Height", ylim = c(45,85), axes = F)
plot(Age[Gender=="female"], Height[Gender=="female"], las = 1, main = "Age x Height for Females", xlab = "Age", ylab = "Height", ylim = c(45,85), axes = F)
#edit the "x" axis
axis(side=1, at = c(3, 6, 10), labels = c("3", "6", "10"))
這就是我得到的:第二個圖形的“x”軸已被編輯,我無法返回第一個繪圖。
參考解法
方法 1:
As user20650 stated: call your edits after each plot command. In your case:
par(mfrow=c(1,2))
plot(Age[Gender=="male"], Height[Gender=="male"], las = 1, main = "Age x Height for Males", xlab = "Age", ylab = "Height", ylim = c(45,85), axes = F)
axis(side=1, at = c(3, 6, 10), labels = c("3", "6", "10"))
plot(Age[Gender=="female"], Height[Gender=="female"], las = 1, main = "Age x Height for Females", xlab = "Age", ylab = "Height", ylim = c(45,85), axes = F)
axis(side=1, at = c(3, 6, 10), labels = c("3", "6", "10"))
(by BCArg、rosapluesch)