[R] png scaling problem

Marc Schwartz MSchwartz at mn.rr.com
Fri Sep 2 15:49:02 CEST 2005


On Fri, 2005-09-02 at 15:08 +0200, Knut Krueger wrote:
> but back to the last problem,
> what could be wrong that the ylab is not displayed as expected?
> 
> with regards
> Knut

The TIF files seem to be OK. However, the PNG files, as a result of your
attempt to scale the plot, do not have enough margin space for side = 2
(left). You would need to adjust the settings for par("mar") and perhaps
adjust the overall plot size in the png() call. This is one of the
reasons why trying to scale a bitmapped image is problematic.

If you want to have finer control over the text annotation, use
something like the following:

  # Create just the 'bare' barplot and save the bar
  # midpoints in 'mp'
  mp <- barplot(1:10, xaxt = "n", yaxt = "n", ann = FALSE)

  # Now create the x axis labels, using 'mp' for placement
  # 'cex' controls text size.
  # See ?axis for more details
  axis(1, at = mp, labels = LETTERS[1:10], cex = 1.25)

  # Do the same for the y axis
  axis(2, at = seq(0, 10, 2), cex = 1)

  # Do the x axis label, using mtext()
  # See ?mtext
  mtext(1, line = 3, text = "X Axis Label", cex = 1.5)

  # Same for y axis
  mtext(2, line = 2.5, text = "y Axis Label", cex = 1.5)

  # Now the title
  mtext(3, line = 2, text = "Main Barplot Title", cex = 4)


Again, with the above, be sure to check the output in the target format,
not on the screen. They will not always be the same.

HTH,

Marc Schwartz




More information about the R-help mailing list