Head and toes
Head and toes

Reputation: 659

Editing previous graph after plotting multiple R graphs

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

Answers (2)

baptiste
baptiste

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="+")

enter image description here

Upvotes: 2

PeterK
PeterK

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

Related Questions