[R] Creating Boxpot with R within bash script

Joshua Wiley jwiley.psych at gmail.com
Mon Feb 28 07:23:00 CET 2011


Hi Greg,

When you are running R from a script, you want to divert the output
somewhere.  Depending exactly how you run it, R may nicely push the
text output to a file, but you should specify where you want the
graphics to go yourself.  For example:

## use the PDF graphics device
pdf(file = "boxplot1.pdf", height = 10, width = 10)
## the plot
boxplot(APCP ~ HOUR, data=CAPE.df )
## important otherwise the device is not shutdown and the file saved
dev.off()

There are many other devices.  Here are some documentation references:

?Devices
?dev.off

Another useful tidbit for this type of work if you ever move outside
of base graphics is:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

HTH,

Josh

On Sun, Feb 27, 2011 at 5:03 PM, Fishel, Greg <gfishel at wral.com> wrote:
> I will confess to being very wet behind the ears when it comes to scripting, so with that as a backdrop, here is my question. I can create a box and whisker plot without any problem from the command line, but incorporating that process into a bash script has proved problematic. Below is the portion of the bash script that fails:
>
> R   --save --no-save --vanilla  <<   EOF
>
>
> CAPE.df = read.table ("sref.sfccape.rdu.txt", header=TRUE, sep=" ")
>
> boxplot ( APCP ~ HOUR, data=CAPE.df )
>
> EOF
>
> I have done a lot of searching, but apparently not in the correct places. Anyone's help will be appreciated greatly!
>
>
> Greg Fishel
> Chief Meteorologist
> WRAL-TV
> P.O. Box 12000
> 2619 Western Boulevard
> Raleigh, NC 27606
> 919-821-8992
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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/



More information about the R-help mailing list