Overplotted labels on multi-page png() output

3 views
Skip to first unread message

Ken Williams

unread,
Jul 2, 2009, 10:52:53 AM7/2/09
to Bay Area R Helpers
I'm seeing some bad behavior when using png() output. Here's my code:

-----
png()
plot(1:10, (1:10)^i, xlab="first plot", ylab="first plot", main="first
plot")
lines(1:10, (1:10)^(i+1))

plot(1:10, (1:10)^i, xlab="second plot", ylab="second plot",
main="second plot")
lines(1:10, (1:10)^(i+1))
dev.off()
-----

The first plot (file Rplot001.png) looks fine; the second plot (file
Rplot002.png) is here:

http://groups.google.com/group/help-R/web/Rplot002.png

As you can see, there seems to be some leftover junk from the first
plot infiltrating the second plot.

I'm on OS X 10.5.7, using R.app 1.27, which uses R 2.8.1. Thanks in
advance for any help!

-Ken

Mark Knecht

unread,
Jul 2, 2009, 11:23:02 AM7/2/09
to Ken Williams, Bay Area R Helpers

It seems like one path forward would be to create a second plot using
X11() and plot the second set there. That way it will certainly be
clean.

Hope this helps,
Mark

Ken Williams

unread,
Jul 2, 2009, 12:26:21 PM7/2/09
to Bay Area R Helpers

On Jul 2, 10:23 am, Mark Knecht <markkne...@gmail.com> wrote:
>
> It seems like one path forward would be to create a second plot using
> X11() and plot the second set there. That way it will certainly be
> clean.

That's true, except I'm actually creating dozens of plots and need
them as separate files.

I think I might use a different workaround: keep track of an increment-
variable and do png()...dev.off() myself for each individual plot. I
haven't tried it yet, but I imagine it will work.

Seems like a bug should be filed on http://bugs.r-project.org/, but
when I tried to search for existing 'png' bugs, the search timed out
without returning responses.

-Ken

Mark Knecht

unread,
Jul 2, 2009, 12:57:23 PM7/2/09
to Ken Williams, Bay Area R Helpers
On 7/2/09, Ken Williams <ken...@gmail.com> wrote:
>
>

I'm very new to this but I have some little functions for creating new
devices, switching, deleting, etc. Small but make my code more
readable - to me anyway.

## Simple functions to add new plot, switchTo, etc.
Plot_AddNew = function(...) {
dev.new(...)
return(dev.cur())
}

Plot_SwitchTo = function(MyPlot) {
dev.set(MyPlot)
return(dev.cur())
}
then called like:

RollupEquityPlot <- Plot_AddNew()
Bobcat1EquityPlot <- Plot_AddNew()
Plot_SwitchTo(RollupEquityPlot)

then if I want to switch away and come back I've got some names I can
remember, etc., so things stay a bit more documented.

I'm thinking it could be improved by putting the return values/names
in a data.frame and not have a bunch of variables floating around
cluttering up ls() but I haven't focused on stuff like that yet. I'm
still trying to get multiple lines of different colors on the same
plat. (Newbie!)

Cheers,
Mark

Daniel Levine

unread,
Jul 2, 2009, 2:02:34 PM7/2/09
to Ken Williams, Bay Area R Helpers
It might not be the problem but you should try doing two devices

so the first one would be

png()
CODE
dev.off()

and the second would also have its own png

png()
CODE 2
dev.off()

try that

Daniel Levine

unread,
Jul 2, 2009, 2:03:36 PM7/2/09
to Ken Williams, Bay Area R Helpers
and use names in png to make mutlple files
Reply all
Reply to author
Forward
0 new messages