2015-04-03 109 views
2

我想結合兩個情節,但我的代碼不起作用,這裏是我的代碼。如何在R中結合兩個圖?

a <- runif(10,1,5) 
b <- runif(10,1,5) 
c <- runif(10,1,5) 
d <- runif(10,1,5) 
plot(a,b,pch=2) 
plot(c,d,add=TRUE) 

任何想法如何解決這個問題?

+0

可能是這個鏈接可以幫助HTTP:// stackoverflow.com/questions/18262017/why-does-plot-not-respect -add真 – akrun 2015-04-03 21:00:22

回答

2

使用points功能爲你的第二個 「層」:

a <- runif(10,1,5) 
b <- runif(10,1,5) 
c <- runif(10,1,5) 
d <- runif(10,1,5) 
plot(a, b, pch=2, xlab = "a | c", ylab = "b | d") 
points(c, d, col="blue") 

enter image description here

0

另一種解決方案:

a <- runif(10,1,5) 
b <- runif(10,1,5) 
c <- runif(10,1,5) 
d <- runif(10,1,5) 
plot(a,b,pch=2) 
par(new = T) 
plot(c,d,add=TRUE, axes= F, xlab=NA,ylab=NA) 
axis(4) 

enter image description here