[R] PNG file don't run on mac's?

Don MacQueen macq at llnl.gov
Thu Sep 18 16:40:22 CEST 2008


First of all, please in the future follow the posting guide and 
include a reproducible example. Yours is not, because the objects 
named "bxpdtrail" and "ResultDir" (and maybe others) are not 
available to readers of this list. And you defined a dataframe named 
"size2" but then used one named "size". It's also puzzling why you 
would include an example in which every line was commented out.

That said, the following example works on my Mac. The png files are 
created and can be viewed by Preview.app. You might give it a try.

## note that the column names do not need to be quoted
size <- data.frame(adname=c("_small","","_big","_html"),
                     width=c(300,400,500,300), height = 
c(300,400,500,300), pointsize =
), cexsize=
                     c(0.6,0.65,0.7,0.65) )

ResultDir <- 'emwout'

for(rol in 1:4) {
   save.at <- file.path(ResultDir,as.character(size[rol,5]))
   fname <- file.path(save.at,paste("graf.1",size[rol,1],".png",sep=""))
   cat('filename: ',fname,'\n')

   ## I have no idea what the restoreConsole argument in png() was 
supposed to do
   ## I don't see it documented in ?png. And 
help.search('restoreConsole') finds nothing. So I took it out.
   png(filename = fname, width= size[rol,2], height = size[rol,3], 
pointsize = size[rol,4], bg = "white" )

   parset <- par(mfrow = c(2,2), oma =  c(0,0,1,0), 
cex.axis=size[rol,6], cex=size[rol,6])




It also looks like your email was line wrapped to perhaps 80 
characters, which makes it hard to read,
and also inconvenient to work with. If you can find a way to avoid 
that, it would be good.

At 11:37 AM +0200 9/18/08, Tom Willems wrote:
>Dear R users,
>I 'm having problems with creating PNG graphic outputs.
>Usualy i create reports in HTML format, containing PNG graphics, so they
>can ealsaly be exported to word and xl and so on.
>On a windows pc that i use at work all works fine, but it never works on
>my mac.
>The HTML's i create on windows, open under safari but the graphics never
>open? is there a way of creating gif's for example?
>Then i was wondering whether there is a less codeing intensif way to
>create plots?
>What i mean is, when i create a plot, existing out of 4 subplots, and i
>want to save it as a PNG to incorporate it in to a HTML.output
>i need to creat every plot under the PNG declaration.
># png(filname..
># parset <- par(mfrow = c(2,2), oma = c(0,0,1,0),..])
># plot(...
># plot(...
># plot(...
># plot(...
># par(parset)
># dev.off()
>Now, because i create graphs for different people, i usualy generate them
>in differerent sizes and configurations.
>So they just have to choose wich one to use in their text.
>  There for i am looking for a way of programming that can save time and
>yet the example below does not work, it only writes tables of data
># plot.1 <- plot(...
># plot.2 <- plot(...
># plot.3 <- plot(...
># plot.4  <- plot(...
># png(..
># plot.1
># dev.off()
># ...
># png(filname..
># parset <- par(mfrow = c(2,2), oma = c(0,0,1,0),..])
># plot.1
># plot.2
># plot.3
># plot.4
># par(parset)
># dev.off()
>Here is an example of how i create the png files that i use in the HTML
># size2 <- data.frame("adname"=c("_small","","_big","_html"),
>"width"=c(300,400,500,300), "height" = c(300,400,500,300), "pointsize" =
>c(10,12,14,10),"Directory"=c(rep("graph",3),"html" ), "cexsize"=
>c(0.6,0.65,0.7,0.65) )
># for(rol in 1:4) {
># save_at <-file.path(ResultDir,as.character(size[rol,5]))
># setwd( save_at)
># x11()
># png(filename = paste("graf_1",size[rol,1],".png",sep=""),width =
>size[rol,2], height = size[rol,3],pointsize = size[rol,4], bg = "white",
>res = NA, restoreConsole =  TRUE)
># parset <- par(mfrow = c(2,2), oma =
># boxplot(bxpdtrail$value,ylab="log10 (x)",
>main=paste("Mean",testname,"at",fase,sep=' '))
># points(1 ,mean(bxpdtrail$value,na.rm=T),  pch = 19)
># arrows(1 , upper(bxpdtrail$value,na.rm=T) , 1 ,
>lower(bxpdtrail$value,na.rm=T), lty=3, code = 3,  angle = 45, length = .1)
># pyramid.plot(pyramiddata$yes,pyramiddata$no,main="Observation of
>Protection",labels=pyramiddata$L1,labelcex=size[rol,6], top.labels =
>c("Protected", "log10(x)", "Unprotected"),xycol=xycol,xxcol=xxcol,gap=8
>,unit = "# animals")
># barplot(pyramiddata$prob_dens,names=pyramiddata$L1,ylab="EPP %",
>xlab="log10(x) ",main="Probability density plot")
># plot(pyramiddata$L1,pyramiddata$prob_cum, ylab="EPP %", xlab="log10(x)
>",main="Cumulative Probability plot", type="S")
># par(parset)
># dev.off()
>#  }
>kind regards,
>Disclaimer: click here
>	[[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>https:// stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http:// www. R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

More information about the R-help mailing list