plotting from dataframes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

plotting from dataframes

condor
This post was updated on .
thanks to your guys help I am closer to solving my problem but I have some small problem. So let's say I start with

>data
number day hour
1 17 10
2 17 11
3 17 6
4 18 4
5 18 10
6 19 8
7 19 8

I want to split to odd days, which I am able to do, I call this object frames, which looks like:

> frames
$`1`
  c1 day1 hour1
1  1   17    10
2  2   17    11
3  3   17     6

$`2`
  c1 day1 hour1
4  6   19     8
5  7   19     8

Now I want to make plots of the hours for all odd days next to each other, but not by hand. I need some sort of loop for this. How is this done?

So
par(mfrow=c(1,2))
for(…) plot(…hours…)

thanks for the help
Reply | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

Andrew Robinson-6
It's not really clear to me what you mean when you say that you want to
plot the hours, so it's hard to help.  Regardless, take a look at looping
and plotting in any of the free documentation on CRAN.

http://cran.r-project.org/other-docs.html

I hope that this helps,

Andrew


On Fri, Jan 18, 2013 at 2:21 AM, condor <[hidden email]> wrote:

> thanks to your guys help I am closer to solving my problem but I have some
> small problem. So let's say I start with
>
> >data
> number day      hour
> 1       17      10
> 2       17      11
> 3       17      6
> 4       18      4
> 5       18      10
> 6       19      8
> 7       19      8
>
> I want to split to odd days, which I am able to do, I call this object
> frames, which looks like:
>
> > frames
> $`1`
>   c1 day1 hour1
> 1  1   17    10
> 2  2   17    11
> 3  3   17     6
>
> $`2`
>   c1 day1 hour1
> 4  6   19     8
> 5  7   19     8
>
> Now I want to make plot of the hours of both days, but not by hand. I need
> some sort of loop for this. How is this done?
>
> So
> par(mfrow=c(1,2))
> for(…) plot(…hours…)
>
> thanks for the help
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>


--
Andrew Robinson
Director (A/g), ACERA
Senior Lecturer in Applied Statistics                      Tel:
+61-3-8344-6410
Department of Mathematics and Statistics            Fax: +61-3-8344 4599
University of Melbourne, VIC 3010 Australia
Email: [hidden email]    Website: http://www.ms.unimelb.edu.au

FAwR: http://www.ms.unimelb.edu.au/~andrewpr/FAwR/
SPuR: http://www.ms.unimelb.edu.au/spuRs/

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

condor
This post was updated on .
So by hand the command would be

par(mfrow=c(1,2))
plot(frames$'1'$hour1)
plot(frames$'2'$hour1)

But in my case there are far more than 2 days, so I want to use a loop. Suppose I have 10 days I want to plot
par(mfrow=c(2,5))
for(i in 1:10){
plot( what should be put here??)
}
Reply | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

PIKAL Petr
Hi

> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of condor
> Sent: Friday, January 18, 2013 10:17 AM
> To: [hidden email]
> Subject: Re: [R] plotting from dataframes
>
> So by hand the command would be
>
> par(mfrow=c(1,2))
> plot(frames$'1'hour1)
> plot(frames$'2'hour1)
>
> But in my case there are far more than 2 days, so I want to use a loop.
> Suppose I have 10 plots
> par(mfrow=c(2,5))
> for(i in 1:10){
> plot( /what should be put here??/)

use
plot[,i]

if you want plot columns 1:10 or

put this
col.to.plot=c(5,7,9,12,15, 17, 21, 25, 26, 30)
in front of cycle and use

plot[,col.to.plot[i]]

if you want to plot preselected columns

Regards
Petr

> }
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/plotting-
> from-dataframes-tp4655851p4655931.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

Rui Barradas
In reply to this post by condor
Hello,

Maybe instead of a loop, you could try

lapply(frames, function(y) plot(y$hour1))

Hope this helps,

Rui Barradas

Em 18-01-2013 09:16, condor escreveu:

> So by hand the command would be
>
> par(mfrow=c(1,2))
> plot(frames$'1'hour1)
> plot(frames$'2'hour1)
>
> But in my case there are far more than 2 days, so I want to use a loop.
> Suppose I have 10 plots
> par(mfrow=c(2,5))
> for(i in 1:10){
> plot( /what should be put here??/)
> }
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851p4655931.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

Jeff Newmiller
In reply to this post by condor
You need to (re-) read the Introduction to R document that comes with R, particularly about indexing lists.

Briefly, there are three ways: integer, string, and approximate string indexing. You seem to be stuck now using approximate string indexing with the $ operator. Integer indexing is more appropriate for your loop.

for(i in 1:10){
plot( frames[[ i ]]$hour1 )
}

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

condor <[hidden email]> wrote:

>So by hand the command would be
>
>par(mfrow=c(1,2))
>plot(frames$'1'hour1)
>plot(frames$'2'hour1)
>
>But in my case there are far more than 2 days, so I want to use a loop.
>Suppose I have 10 plots
>par(mfrow=c(2,5))
>for(i in 1:10){
>plot( /what should be put here??/)
>}
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851p4655931.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: plotting from dataframes

arun kirshna
In reply to this post by condor
Hi,
May be this helps:
frames<-list(data.frame(c1=1:3,day1=17,hour1=c(10,11,6)),data.frame(c1=6:7,day1=19,hour1=8),data.frame(c1=8:10,day1=21,hour1=c(11,15,18)),data.frame(c1=12:13,day1=23,hour1=7))
par(mfrow=c(2,2))
lapply(seq_along(frames),function(i) plot(frames[[i]][,3]))
A.K.




----- Original Message -----
From: condor <[hidden email]>
To: [hidden email]
Cc:
Sent: Friday, January 18, 2013 4:16 AM
Subject: Re: [R] plotting from dataframes

So by hand the command would be

par(mfrow=c(1,2))
plot(frames$'1'hour1)
plot(frames$'2'hour1)

But in my case there are far more than 2 days, so I want to use a loop.
Suppose I have 10 plots
par(mfrow=c(2,5))
for(i in 1:10){
plot( /what should be put here??/)
}



--
View this message in context: http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851p4655931.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.