Hello What's the differente betwen using "plot" and using "print" in order to plot a graph? For example in order to plot the result of a histogram. cheers -- View this message in context: http://r.789695.n4.nabble.com/plot-vs-print-tp3045256p3045256.html Sent from the R help mailing list archive at Nabble.com.
Hi, It really depends, but almost always to plot a graph you would use plot() (or some similar graphing function). print() is usually more for displaying data in the console, not graphically. There are some cases (e.g., inside a for loop), where you need to wrap the call to plot (or similar graphing function) in print() (lattice graphics is probably the most common example here). Here is an example/demonstration of plot() and print() in the context of a histogram (which was calculated and saved into an object called 'x'): ## do histogram calculations but do not plot x <- hist(rnorm(1000), plot = FALSE) ## print() just shows you the data print(x) ## put data in a graph plot(x) ## but you could also just use hist() without plot() or print() hist(runif(100)) HTH, Josh On Tue, Nov 16, 2010 at 9:09 AM, skan <juanpide at gmail.com> wrote:> > Hello > > What's the differente betwen using "plot" and using "print" ?in order to > plot a graph? > For example in order to plot the result of a histogram. > > cheers > -- > View this message in context: http://r.789695.n4.nabble.com/plot-vs-print-tp3045256p3045256.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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 Tue, Nov 16, 2010 at 11:09 AM, skan <juanpide at gmail.com> wrote:> What's the differente betwen using "plot" and using "print" ?in order to > plot a graph? > For example in order to plot the result of a histogram.Could you give an example? It seems that you are referring to graphics functions in packages such as lattice and ggplot2 that produce objects that must be print'ed or plot'ed before they are rendered on a graphics device. However, we would need to know if you mean the result of histogram() in the lattice package or hist() in the graphics package before we could answer.
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f On Nov 16, 2010, at 12:09 PM, skan wrote:> > Hello > > What's the differente betwen using "plot" and using "print" in > order to > plot a graph? > For example in order to plot the result of a histogram. > > cheers > --David Winsemius, MD West Hartford, CT
Well, assuming this refers to the histogram function in the lattice package, looking at the code for print.trellis shows that the default behavior is to call plot.trellis with the same arguments. So unless you change the default behavior, there really is no difference between printing and plotting (except maybe one more step in the call stack). Using print can allow you to do something else if you set the print.function option in lattice to something else. The idea of "printing" graphs to plot them comes because the R interpreter will print (call the print method) on objects that are returned from functions at the top level and not saved into a variable (and possibly other cases), having a print method that plots means that calls to histogram and others without saving or doing other things will cause the object to be plotted, which is generally what the user wants. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of skan > Sent: Tuesday, November 16, 2010 10:10 AM > To: r-help at r-project.org > Subject: [R] plot vs print ?? > > > Hello > > What's the differente betwen using "plot" and using "print" in order > to > plot a graph? > For example in order to plot the result of a histogram. > > cheers > -- > View this message in context: http://r.789695.n4.nabble.com/plot-vs- > print-tp3045256p3045256.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.