[R] Q: obtaining non-transparent background in png
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Jul 31 19:00:17 CEST 2007
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
day 05
svn rev 42131
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 at 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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list