Common legend for two plots
With layout
Impossible to put a common title correctly
layout(mat=matrix(c(3, 1, 4, 2), ncol=2), heights = c(10, 90))
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 2, y = 2, col = "red")
plot(x = 2, y = 2, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 1, y = 1, col = "red")
par(mar=c(0, 0, 0, 0)+0)
plot.new()
text(x=1, y=0.5, labels = "Common title", cex=2, pos=2)
plot.new()
text(x=0, y=0.5, labels = "for both graphics", cex=2, pos=4)
layout(1)
With par(fig=c(x1, x2, y1, y2))
It is more easy to set up exact position of ploting region
# restore all par() values to their defaults
dev.off()
plot.new()
par(fig=c(0, 0.5, 0, 0.9))
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 2, y = 2, col = "red")
par(fig=c(0.5, 1, 0, 0.9), new = TRUE)
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 2, y = 2, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 1, y = 1, col = "red")
par(fig=c(0, 1, 0.9, 1), new = TRUE)
par(mar=c(0, 0, 0, 0)+0)
plot.new()
text(x=0.5, y=0.9, labels = "Common title for both graphics", cex=par("cex.main"), pos=1)
Impossible to put a common title correctly
layout(mat=matrix(c(3, 1, 4, 2), ncol=2), heights = c(10, 90))
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 2, y = 2, col = "red")
plot(x = 2, y = 2, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 1, y = 1, col = "red")
par(mar=c(0, 0, 0, 0)+0)
plot.new()
text(x=1, y=0.5, labels = "Common title", cex=2, pos=2)
plot.new()
text(x=0, y=0.5, labels = "for both graphics", cex=2, pos=4)
layout(1)
With par(fig=c(x1, x2, y1, y2))
It is more easy to set up exact position of ploting region
# restore all par() values to their defaults
dev.off()
plot.new()
par(fig=c(0, 0.5, 0, 0.9))
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 1, y = 1, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 2, y = 2, col = "red")
par(fig=c(0.5, 1, 0, 0.9), new = TRUE)
par(mar=c(4, 4, 1, 1)+0.4)
plot(x = 2, y = 2, ylim = c(0, 2), xlim = c(0, 2), bty="n")
points(x = 1, y = 1, col = "red")
par(fig=c(0, 1, 0.9, 1), new = TRUE)
par(mar=c(0, 0, 0, 0)+0)
plot.new()
text(x=0.5, y=0.9, labels = "Common title for both graphics", cex=par("cex.main"), pos=1)
Commentaires
Enregistrer un commentaire