Re: [R] Q: obtaining non-transparent background in png
Prof Brian Ripley said the following at 07/31/2007 12:20 PM : > You are *copying* the plot, and that means copying the background too (it > *is* part of the plot). Almost certainly the plot you are copying had a > transparent background: that is the default for X11. > > All the confusion seems to be over misreadings of this. > But following that logic, changing the size of the plot shouldn't work either. I don't think you can have it both ways. I.e., either it's OK to change the size and the background, or it's not OK to change either of them. There's no way to deduce from the word "copy" that you're allowed to change some things but not others; I think that's where the confusion enters. __ R-help@stat.math.ethz.ch 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.
Re: [R] Q: obtaining non-transparent background in png
You are *copying* the plot, and that means copying the background too (it *is* part of the plot). Almost certainly the plot you are copying had a transparent background: that is the default for X11. All the confusion seems to be over misreadings of this. On Tue, 31 Jul 2007, Gavin Simpson wrote: > On Tue, 2007-07-31 at 10:22 -0600, D. R. Evans wrote: >> I am not understanding something about generating PNG plots. >> >> I have tried several ways to obtain something other than a transparent >> background, but nothing I've done seems to change the background. >> >> For example: >> >> dev.print(png, width=800, height=600, bg='red', filename='example.png') >> >> which I thought would give a red background, simply gives the same >> transparent background I always get. > > ?dev.print says: > > 'dev.print' copies the graphics contents of the current device to > a new device which has been created by the function specified by > 'device' and then shuts the new device. > > Note "copies" - given that you've already drawn a figure with a white > background, should this then produce one that is red? However, you are > correct that it does produce a plot with a transparent background. > > I find it easier to wrap my plotting commands in the relevant device, > e.g. this works with the desired background: > >> png("mypng.png", height = 400, width = 400, bg = "red", > pointsize = 12) >> plot(1:10) >> dev.off() > > Whereas these do not give "red" backgrounds as one might have expected, > but transparent ones: > >> plot(1:10) >> dev.print(png, height = 400, width = 400, bg = "red", pointsize = 12, >filename = "mypng2.png") > X11 > 2 >> dev.copy(png, height = 400, width = 400, bg = "red", pointsize = 12, > filename = "mypng3.png") > PNG > 3 >> dev.off() > X11 > 2 > > Not sure whether this is as intentional or not, but it does not appear > to be passing the bg argument on to the 'device', or if it does, it is > not being used/respected - perhaps all that is need is clarification as > to what can be specified in '...' in ?dev.print > >> version > _ > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status Patched > major 2 > minor 5.1 > year 2007 > month 07 > day05 > svn rev42131 > language R > version.string R version 2.5.1 Patched (2007-07-05 r42131) > > G > >> >> And I also don't understand why the default background is transparent, >> when the documentation seems to say that it's white: >> png(filename = "Rplot%03d.png", width = 480, height = 480, >> pointsize = 12, bg = "white", res = NA,...) >> >> (This is on a Kubuntu dapper 64-bit system.) >> >> [I looked through the mail archives, and there seem to be a few very >> old postings talking about the opposite problem, but nothing recent; >> so I conclude that I'm doing something wrong.] >> >> __ >> R-help@stat.math.ethz.ch 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. > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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.
Re: [R] Q: obtaining non-transparent background in png
On 31/07/07, Gavin Simpson <[EMAIL PROTECTED]> wrote: > On Tue, 2007-07-31 at 10:22 -0600, D. R. Evans wrote: > > I am not understanding something about generating PNG plots. > > > > I have tried several ways to obtain something other than a transparent > > background, but nothing I've done seems to change the background. > > > > For example: > > > > dev.print(png, width=800, height=600, bg='red', filename='example.png') > > > > which I thought would give a red background, simply gives the same > > transparent background I always get. > > ?dev.print says: > > 'dev.print' copies the graphics contents of the current device to > a new device which has been created by the function specified by > 'device' and then shuts the new device. > > Note "copies" - given that you've already drawn a figure with a white > background, should this then produce one that is red? Well, I wondered about that, so the first thing I did was to test it by changing a different parameter. I created an X11 plot with the default size (480, I think?) and then printed it to a png with a width of 800. That indeed created a PNG file of width 800, so I deduced from that that it was OK to change the parameters of the plot in the destination device. > Not sure whether this is as intentional or not, but it does not appear > to be passing the bg argument on to the 'device', or if it does, it is > not being used/respected - perhaps all that is need is clarification as > to what can be specified in '...' in ?dev.print I think so. Either that or it seems to be a bug (I obviously don't know enough about how things are supposed to work to make that determination; but it does seem rather bug-like behaviour, especially since one can certainly change some of the parameters associated with the plot). Anyway, it seems like I need an explicit "par(bg='red')" before performing any graphical operations. That seems to do the trick. Although it's still not clear how one would solve the general problem in which one has an X11 plot with background colour A, but wants to copy it to a PNG with background colour B... Weirdly (at least it seems weird to me) I just tried the following with an unexpected result: I created the following function: "to.png" <- function(FILENAME = 'Rplot%03d.png') { par(bg='blue') dev.print(png, width=800, height=600, filename=FILENAME) } par(bg='red') plot(1:10)# ok, I get a red plot to.png('should-be-blue.png') # png is red, not blue plot(1:10) # now it's blue (as I sort-of expected) So it isn't obvious that there's anything one can put in the to.png() function that will control the colour of the background for the PNG output. __ R-help@stat.math.ethz.ch 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.
Re: [R] Q: obtaining non-transparent background in png
On Tue, 2007-07-31 at 10:22 -0600, D. R. Evans wrote: > I am not understanding something about generating PNG plots. > > I have tried several ways to obtain something other than a transparent > background, but nothing I've done seems to change the background. > > For example: > > dev.print(png, width=800, height=600, bg='red', filename='example.png') > > which I thought would give a red background, simply gives the same > transparent background I always get. ?dev.print says: 'dev.print' copies the graphics contents of the current device to a new device which has been created by the function specified by 'device' and then shuts the new device. Note "copies" - given that you've already drawn a figure with a white background, should this then produce one that is red? However, you are correct that it does produce a plot with a transparent background. I find it easier to wrap my plotting commands in the relevant device, e.g. this works with the desired background: > png("mypng.png", height = 400, width = 400, bg = "red", pointsize = 12) > plot(1:10) > dev.off() Whereas these do not give "red" backgrounds as one might have expected, but transparent ones: > plot(1:10) > dev.print(png, height = 400, width = 400, bg = "red", pointsize = 12, filename = "mypng2.png") X11 2 > dev.copy(png, height = 400, width = 400, bg = "red", pointsize = 12, filename = "mypng3.png") PNG 3 > dev.off() X11 2 Not sure whether this is as intentional or not, but it does not appear to be passing the bg argument on to the 'device', or if it does, it is not being used/respected - perhaps all that is need is clarification as to what can be specified in '...' in ?dev.print > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Patched major 2 minor 5.1 year 2007 month 07 day05 svn rev42131 language R version.string R version 2.5.1 Patched (2007-07-05 r42131) G > > And I also don't understand why the default background is transparent, > when the documentation seems to say that it's white: > png(filename = "Rplot%03d.png", width = 480, height = 480, > pointsize = 12, bg = "white", res = NA,...) > > (This is on a Kubuntu dapper 64-bit system.) > > [I looked through the mail archives, and there seem to be a few very > old postings talking about the opposite problem, but nothing recent; > so I conclude that I'm doing something wrong.] > > __ > R-help@stat.math.ethz.ch 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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch 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.
Re: [R] Q: obtaining non-transparent background in png
Both of these work for me: par(bg="red") plot(1:10) dev.print(png, width=800, height=600, filename="tmp.png") and png("tmp.png", width=800, height=600, bg="red") plot(1:10) dev.off() Best, Jim D. R. Evans wrote: > I am not understanding something about generating PNG plots. > > I have tried several ways to obtain something other than a transparent > background, but nothing I've done seems to change the background. > > For example: > > dev.print(png, width=800, height=600, bg='red', filename='example.png') > > which I thought would give a red background, simply gives the same > transparent background I always get. > > And I also don't understand why the default background is transparent, > when the documentation seems to say that it's white: > png(filename = "Rplot%03d.png", width = 480, height = 480, > pointsize = 12, bg = "white", res = NA,...) > > (This is on a Kubuntu dapper 64-bit system.) > > [I looked through the mail archives, and there seem to be a few very > old postings talking about the opposite problem, but nothing recent; > so I conclude that I'm doing something wrong.] > > __ > R-help@stat.math.ethz.ch 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. -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 __ R-help@stat.math.ethz.ch 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.
[R] Q: obtaining non-transparent background in png
I am not understanding something about generating PNG plots. I have tried several ways to obtain something other than a transparent background, but nothing I've done seems to change the background. For example: dev.print(png, width=800, height=600, bg='red', filename='example.png') which I thought would give a red background, simply gives the same transparent background I always get. And I also don't understand why the default background is transparent, when the documentation seems to say that it's white: png(filename = "Rplot%03d.png", width = 480, height = 480, pointsize = 12, bg = "white", res = NA,...) (This is on a Kubuntu dapper 64-bit system.) [I looked through the mail archives, and there seem to be a few very old postings talking about the opposite problem, but nothing recent; so I conclude that I'm doing something wrong.] __ R-help@stat.math.ethz.ch 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.