Reputation: 18239
Here is my first plot
par(bg="white")
image(m, main = paste("generation: ",generation), ylab="", col=heat.colors(100), xaxt="n", yaxt="n", xlab="")
It is a square, and I'd like it to be a rectangle. So I did
par(bg="white", mar=c(16,1,16,1))
image(m, main = paste("generation: ",generation), ylab="", col=heat.colors(100), xaxt="n", yaxt="n", xlab="")
But then the title (main
) is really far away from the plot. So I did
par(bg="white", mar=c(16,1,16,1))
image(m, ylab="", col=heat.colors(100), xaxt="n", yaxt="n", xlab="")
legend(0.32, 3.5, paste("Generation: ", IntFormat(generation, 4)), border="white", xpd=TRUE, box.col="white", cex=1.5)
Well.. I wouldn't say it is splendid, but I was satisfied. So let's put that into a .png
png(paste0(folder.images, "pg_",IntFormat(generation,4),".png"))
par(bg="white", mar=c(16,1,16,1))
image(m, ylab="", col=heat.colors(100), xaxt="n", yaxt="n", xlab="")
legend(0.32, 3.5, paste("Generation: ", IntFormat(generation, 4)), border="white", xpd=TRUE, box.col="white", cex=1.5)
dev.off()
and here is what the .png looks like!
Is there a better solution to make a rectangle out of my square than using the parameter mar
that force me to add a title with legend
and to search by trial and error where the center to the picture is for the title.
Why is the .png different from what is shown in the R window?
Upvotes: 1
Views: 2246
Reputation:
I could achieve this:
png("test.png", res = 150, width = 8, height = 1, units = "in")
par(mar = c(1,1,1,1))
image(matrix(1:10, ncol=1), ylab="", col=heat.colors(100), xaxt="n",
yaxt="n", xlab="", main="Generation: 0001")
dev.off()
Upvotes: 3