Im developing a function that uses ggplot2 to create multiple graphs that compares two set of points representing shapes.
ref = matrix(c(1,3,1,3,2,2,4,4),nrow=4, ncol=2)
ref<-data.frame(x=ref[,1], y=ref[,2])
shapes<-list()
shapes[[1]]<-matrix(c(1.5,2.9,1.4,3.1,2.2,2.3,4.5,3.5),nrow=4, ncol=2)
shapes[[2]]<-matrix(c(0.5,3.9,1.1,3.1,1.8,2,4.5,3.5),nrow=4, ncol=2)
shapes[[3]]<-matrix(c(1.8,3.2,1,3.5,2.2,2.3,4.5,3.5),nrow=4, ncol=2)
newplots<-list()
for(i in 1:length(shapes)){
target<-shapes[[i]]
vari<-data.frame(x=target[,1], y=target[,2])
newplots[[i]]<-ggplot(ref,aes(x = x,y = y)) + geom_point(size=2,color="red")+coord_fixed()+
geom_point(data=vari,aes(x=x,y=y),color="black",size=3)
}
newplots[[1]]
newplots[[2]]
newplots[[3]]
newplots[[4]]
The problem is that the reference points seem to "move" from plot to plot when they suppose to stay in the same place.