[R] Generate and store multiple plots

1 view
Skip to first unread message

anal...@hotmail.com

unread,
Jun 10, 2012, 9:47:38 PM6/10/12
to r-h...@r-project.org
I have a data set whose rows look like

Item date variable_1 variable_2 variable_3 variable_4


Different items may occur over different dates.

During any single study, I might select a subset of the four variables
or some function of them to be plotted against time (date).

For each item, I would select a date range and I want a plot of the
selected variables over that range for that item.

I need a method that would do this at one shot and put the plot
objects out to disk, one for each item.

Thanks.

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

David Winsemius

unread,
Jun 10, 2012, 11:00:51 PM6/10/12
to anal...@hotmail.com, r-h...@r-project.org

On Jun 10, 2012, at 9:47 PM, anal...@hotmail.com wrote:

> I have a data set whose rows look like
>
> Item date variable_1 variable_2 variable_3 variable_4
>
>
> Different items may occur over different dates.
>
> During any single study, I might select a subset of the four variables
> or some function of them to be plotted against time (date).
>
> For each item, I would select a date range and I want a plot of the
> selected variables over that range for that item.
>
> I need a method that would do this at one shot and put the plot
> objects out to disk, one for each item.

What efforts at construction of test cases can you show us?

--

David Winsemius, MD
West Hartford, CT

Jim Lemon

unread,
Jun 11, 2012, 12:18:08 AM6/11/12
to anal...@hotmail.com, r-h...@r-project.org
On 06/11/2012 11:47 AM, anal...@hotmail.com wrote:
> I have a data set whose rows look like
>
> Item date variable_1 variable_2 variable_3 variable_4
>
>
> Different items may occur over different dates.
>
> During any single study, I might select a subset of the four variables
> or some function of them to be plotted against time (date).
>
> For each item, I would select a date range and I want a plot of the
> selected variables over that range for that item.
>
> I need a method that would do this at one shot and put the plot
> objects out to disk, one for each item.
>
Hi analyst41,
You probably want to write a custom function something like this:

plot_varying<-function(x,which_vars=3:6,which_item=NA,
start_date,end_date) {

# open an output device with an unique name
png(paste(which_item,format(start_date,"%d%m%Y"),
format(end_date,"%d%m%Y"),".png",sep="_")
# get the plot dimensions
ylim<-range(x[x$item==which_item,which_vars[1]])
# plot all the requested variables
matplot(x[x$item==which_item,which_vars],ylim=ylim,...)
dev.off()
}

Then call your function for each item, variables and dates.

Jim
Reply all
Reply to author
Forward
0 new messages