Set plot margin of png plot device using par

后端 未结 1 1220
星月不相逢
星月不相逢 2021-01-20 05:48

I\'ve created a choropleth of Brazil. When saving the plot in .png, the upper and the lower part of the plot are lost (covered). Here are the lines to save the plot.

相关标签:
1条回答
  • 2021-01-20 06:04

    From Details in ?par:

    Each device has its own set of graphical parameters.

    Thus, even though I had set the outer margin of the plot in par (omi = c(0,0,0,0)), those value were overwritten by the parameters in png when saving the plot.

    The solution was to set the margin parameters in par after calling png

    plot.new()
    
    # first open png device...
    png(filename = "map_cons_g.png", width = 6,height = 6, units = "in", res = 600)
    
    # ...then set par
    par(omi = c(0,0,0,0), mgp = c(0,0,0), mar = c(0,0,0,0), family = "D")
    par(mfrow = c(1, 1), cex = 1, cex.lab = 0.75, cex.main = 0.2, cex.axis = 0.2)
    
    plot(c(-75, -35), c(5, -33),  type = "n", axes = FALSE, xlab = "", ylab = "", asp = 1.2)
    plot(Brazil, col = cols[Brazil$Cons.g_ri], add = TRUE, border = "black", lwd = 0.5)
    dev.off()
    
    0 讨论(0)
提交回复
热议问题