I can plot to png's fine when i run this directly from the top-level
script/console:
png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
But for some reason it's not working when that's in a function:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
I suspect this is because the qplot's return value must be "returned"
to the top-level, because this works:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
Any hints on how I can plot from within a function? Thanks in advance.
Plotting from functions
5 messages · Yang Zhang, Joshua Wiley, Duncan Murdoch +1 more
On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang <yanghatespam at gmail.com> wrote:
I can plot to png's fine when i run this directly from the top-level
script/console:
png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
But for some reason it's not working when that's in a function:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
I suspect this is because the qplot's return value must be "returned"
to the top-level, because this works:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
Any hints on how I can plot from within a function? ?Thanks in advance.
Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions?
Hi, Within functions, you often do need to wrap the plotting calls in print() (you would see this if you read the FAQ). Cheers, Josh
On Wed, Jun 1, 2011 at 1:06 PM, Yang Zhang <yanghatespam at gmail.com> wrote:
On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang <yanghatespam at gmail.com> wrote:
I can plot to png's fine when i run this directly from the top-level
script/console:
png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
But for some reason it's not working when that's in a function:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
I suspect this is because the qplot's return value must be "returned"
to the top-level, because this works:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
Any hints on how I can plot from within a function? ?Thanks in advance.
Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions?
______________________________________________ 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.
Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
On 01/06/2011 4:06 PM, Yang Zhang wrote:
On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang<yanghatespam at gmail.com> wrote:
I can plot to png's fine when i run this directly from the top-level
script/console:
png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
But for some reason it's not working when that's in a function:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
I suspect this is because the qplot's return value must be "returned"
to the top-level, because this works:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
Any hints on how I can plot from within a function? Thanks in advance.
Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions?
If the plotting function is using grid graphics you do. I don't know where the qplot() function is from, but it looks as though it must be from a package that uses grid. Duncan Murdoch
On 02/06/11 10:13, Duncan Murdoch wrote:
On 01/06/2011 4:06 PM, Yang Zhang wrote:
On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang<yanghatespam at gmail.com> wrote:
I can plot to png's fine when i run this directly from the top-level
script/console:
png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()
But for some reason it's not working when that's in a function:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})()
I suspect this is because the qplot's return value must be "returned"
to the top-level, because this works:
(function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off()
Any hints on how I can plot from within a function? Thanks in advance.
Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions?
If the plotting function is using grid graphics you do. I don't know where the qplot() function is from, but it looks as though it must be from a package that uses grid. Duncan Murdoch _
qplot is from ggplot2, and is a simpler form of ggplot with limited features. David Scott
_________________________________________________________________ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.scott at auckland.ac.nz, Fax: +64 9 373 7018