[R] losing x-label when exporting to PNG

John Kane jrkrideau at yahoo.ca
Thu Apr 27 14:43:04 CEST 2006


I have a simple barplot that looks fine in the R
graphics device window. However when I export it to
png I am losing the x-label.  It must be an obvious
problem but I cannot see it. Trying to resize the plot
does not seem to  help.  Code is below.

Any help gratefully received.

###### Start Code############

Groups <-c(21.8,45,  43, 17.2, 8.3,  18)
names(Groups) <- c("Exeter", "Halifax", "Moosonee",
"Ottawa",
          "Montréal", "Saskatoon")
# Here we are setting the font to Bold and addin some
lines to the bottom
# margin of the graph, 6 vs default of 5, to give us
more room with the angled
# labels.

par(font=2,mar= (c(6, 4, 4, 2) + 0.1))

Mycolours <- c("red", "blue", "green", "yellow",
"orange" ,"purple")

# --------------plot to screen
--------------------------------------
mp <- barplot(Groups, beside=T ,
      horiz=F , las=1, ylim=c(0,60),  axisnames=F,
font.lab=2, col=Mycolours
      )
text(mp, par("usr")[3] - 1.5, srt = 45, adj = 1,
labels = names(Groups), xpd = T ,
     cex=.75,
   )
   
mtext(side = 1, line=5, text="% of  Services above
thresholds ")
mtext(side=2, line=2.5, text="Percent")
title(main="")
box()
 # -------------------plot to png
file------------------------------
png('gr_%04d.png', width=600, height=400)
mp <- barplot(Groups, beside=T ,
      horiz=F , las=1, ylim=c(0,60),  axisnames=F,
font.lab=2, col=Mycolours
      )
text(mp, par("usr")[3] - 1.5, srt = 45, adj = 1,
labels = names(Groups), xpd = T ,
     cex=.75,
   )
   
mtext(side = 1, line=5, text="% of  Services above
thresholds ")
mtext(side=2, line=2.5, text="Percent")
title(main="")
box()

dev.off()

####   End code #####




More information about the R-help mailing list