That worked!  Thank you very much for the help. 
 
I think I have one last question about qplot in ggplot2, That is exporting the 
plot to JPG while in a loop.   I tried what was recommended in "Re: [R] jpeg() 
creating empty files with qplot() in a loop", however, I received some errors 
(see below).  I also tried using a PDF, but that did not work either, i.e. the 
PDF produced was blank.  Oddly enough the results produced using 
"dev.print(file="qplot_output.jpg", device=jpeg, width=600) " in a loop are 
blank, i.e. the JPG file is there, but it is blank.  Unfortunately,  
"ggsave(file="ggsave_qplot_output.jpg")" does not even produce a JPG file 
output.  Any help at this point is greatly appreciated.  Is the problem related 
to the fact that I need to use the plain "hist" and "dev.print" prior to using 
ggplot's qplot? 
 
Thanks again for all your help.   

 
> for(jj in 0:4)
+ {
+   rnorm_test_data<-rnorm(1000,3,6)
+   hist(rnorm_test_data)
+   dev.print(file="test_data.jpg", device=jpeg, width=600) 
+ 
+   plot.new()  
+   qplot(rnorm_test_data, geom = "histogram", binwidth = 1) + 
+         scale_x_continuous("Test Data") + scale_y_continuous("Frequency") + 
+         scale_fill_discrete("qplot histogram")
+   
+   # Print the plot to a JPG or PDF 
+   dev.print(file="qplot_output.jpg", device=jpeg, width=600)   
+   ggsave(file="ggsave_qplot_output.jpg") 
+   ggsave(file = "ggsave_qplot_output.pdf")
+ 
+ }      
Saving 6.9" x 6.89" image
Error in get(as.character(FUN), mode = "function", envir = envir) : 
  variable "jpg" of mode "function" was not found
> 

 

 
 
g 6.9" x 6.89" image
Error in get(as.character(FUN), mode = "function", envir = envir) : 
  variable "jpg" of mode "function" was not found
 
P.S. Here is the 
> sessionInfo()
R version 2.8.0 (2008-10-20) 
i386-pc-mingw32 
locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   
base     
other attached packages:
 [1] ggplot2_0.8.1      reshape_0.8.2      RColorBrewer_1.0-2 
proto_0.3-8        plyr_0.1.4         nortest_1.0        fBasics_280.74     
timeSeries_290.79 
 [9] timeDate_290.81    vcd_1.2-1          MASS_7.2-44        colorspace_1.0-0  


--- On Tue, 1/6/09, ONKELINX, Thierry <thierry.onkel...@inbo.be> wrote:

From: ONKELINX, Thierry <thierry.onkel...@inbo.be>
Subject: RE: [R] R Stacked Histogram
To: jasonkrup...@yahoo.com, r-help@r-project.org
Date: Tuesday, January 6, 2009, 9:54 AM

Dear Jason,

Have a look at scale_y_continuous() and scale_fill_discrete(). This might work
(untested as your example is not reproducible with a (dummy) dataset).

qplot(Age, data = recerts_combined_values, binwidth = 5, fill =
combined_values$Test.Type, main="Combined Age Histogram") +
scale_x_continuous("Age, months") +
scale_y_continuous("Counts") + scale_fill_discrete("Type of
Tests")

HTH,

Thierry


----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology
and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
thierry.onkel...@inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more than
asking him to perform a post-mortem examination: he may be able to say what the
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens
Jason Rupert
Verzonden: dinsdag 6 januari 2009 16:00
Aan: r-help@r-project.org
Onderwerp: Re: [R] R Stacked Histogram

Great advice.  I did a quick read and came up with the following:
 
qplot(Age, data = recerts_combined_values, binwidth = 5, 
         fill = combined_values$Test.Type, 
         ylab="Counts", xlab="Age, months",  
         main="Combined Age Histogram", 
         legend.name = "Type of Tests")

Unfortunatley, here is a description of the results:
(1) the "main" title font size by default is too large and is clipped
by the image (guess I need to figure out how to fix this), 
(2) ylab appears to fail - it does not replace the default "count"
label - what should I do to fix this?
(3) like (2), neither using "legend.name" nor
"legend.title" appears to replace/change the name of the legend
title/name.  
 
By any chance can you provide some advice for tackeling these items?  These
are probably due to me being a noobie on the ggplot2 package.  
 
Thanks again.
 

--- On Mon, 1/5/09, hadley wickham <h.wick...@gmail.com> wrote:

From: hadley wickham <h.wick...@gmail.com>
Subject: Re: [R] R Stacked Histogram

Cc: r-help@r-project.org
Date: Monday, January 5, 2009, 7:42 AM


wrote:
> Understood.  Will head the warning about odd way to display data.
>
> Any recommendations about where I look to find full details about
"qplot".
>
> I tried ?qplot, but it did not return full details.
>
> That description was missing a few items, e.g. fill, which is used below.

The best place to start is the qplot chapter of the ggplot2 book -
http://had.co.nz/ggplot2/book

Regards,

Hadley

-- 
http://had.co.nz/



      
        [[alternative HTML version deleted]]


Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd
is
door een geldig ondertekend document. The views expressed in  this message
and any annex are purely those of the writer and may not be regarded as stating

an official position of INBO, as long as the message is not confirmed by a duly

signed document.



      
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to