Reputation: 659
I plotted two graphs:
par(mfrow=c(1,2)) # 2 graphs, positioning them side by side
a<-c(1,2,3)
b<-c(3,6,4)
c<-c(2,5,5)
d<-c(3,4,5)
plot(a,b) #1st graph
plot(c,d) #2nd graph
Say now I want to add a point to the 1st graph (i.e. the graph on the left),
points(2.5,4.5)
how can I do this without restarting the plot again?
Thank you!
Upvotes: 1
Views: 184
Reputation: 77096
par(mfg) can get you there,
par(mfrow=c(2,1), mar=c(0,0,0,0))
plot.new()
grid()
box()
plot.new()
grid()
box()
points(0.5,0.5, col="red")
par(mfg=c(1,1))
points(0.5,0.5, col="blue")
par(mfg=c(2,1))
points(0.5,0.5, col="red", pch="+")
Upvotes: 2
Reputation: 1243
Something has to be carried around. In this case I think it's the underlying data (a,b,c,d). Try
a<-c(1,2,3)
b<-c(3,6,4)
c<-c(2,5,5)
d<-c(3,4,5)
myPlot <- function(){
par(mfrow=c(1,2)) # 2 graphs, positioning them side by side
plot(a,b) #1st graph
plot(c,d) #2nd graph
}
myPlot()
a <- cbind(a,2.5)
b <- cbind(b,4.5)
myPlot()
Upvotes: 0