Skip to content

Plotting using 'if' statements

8 messages · Steve Murray, Henrique Dallazuanna

#
Dear all,

I have a dataset of four columns, and I wish to plot (as a scatter graph) the values of the third column where the values are greater than zero, and the fourth column. 

I tried doing this via the plot command itself, but got into a bit of a mess (resulting in errors!). My dataframe is called 'January':
Error: unexpected '>' in "plot(January[3(>"


After a few variations on this, I thought I'd try making a new object which includes all values from the third column of January>0 (to plot in a separate step) as follows:
No error here. However, when I display the 'values' of JanFilter, it shows that instead of keeping the numerical values, the above operation simply displays the results of the logical test:
Value
[1,]                       FALSE
[2,]                        TRUE
[3,]                        TRUE
[4,]                        TRUE
[5,]                        TRUE
[6,]                        TRUE


This is obviously no good for plotting the numerical values on axes!

So my question is, how do I perform 'if' statements in order to filter out various parts of a dataset, for plotting on a graph.

Many thanks,

Steve
#
Ah that's great, thank you very much.

As a follow-on, in the same format, how would I plot where column 3 is greater than 0 *but also less than 2*?

Once again, any help is much appreciated.


Thanks,

Steve

________________________________
Date: Thu, 4 Sep 2008 13:39:12 -0300
From: wwwhsd at gmail.com
To: smurray444 at hotmail.com
Subject: Re: [R] Plotting using 'if' statements
CC: r-help at r-project.org

Try this:

plot(January[January[,3]> 0, 3:4])
On Thu, Sep 4, 2008 at 1:28 PM, Steve Murray wrote:
Dear all,



I have a dataset of four columns, and I wish to plot (as a scatter graph) the values of the third column where the values are greater than zero, and the fourth column.



I tried doing this via the plot command itself, but got into a bit of a mess (resulting in errors!). My dataframe is called 'January':
Error: unexpected '>' in "plot(January[3(>"





After a few variations on this, I thought I'd try making a new object which includes all values from the third column of January>0 (to plot in a separate step) as follows:
No error here. However, when I display the 'values' of JanFilter, it shows that instead of keeping the numerical values, the above operation simply displays the results of the logical test:
Value

[1,]                       FALSE

[2,]                        TRUE

[3,]                        TRUE

[4,]                        TRUE

[5,]                        TRUE

[6,]                        TRUE





[[elided Hotmail spam]]



So my question is, how do I perform 'if' statements in order to filter out various parts of a dataset, for plotting on a graph.



Many thanks,



Steve



______________________________________________

R-help at r-project.org mailing list



PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




--
Henrique Dallazuanna
Curitiba-Paran?-Brasil
25? 25' 40" S 49? 16' 22" O
#
Thanks again Henrique - that's really useful to know!

_________________________________________________________________
Discover Bird's Eye View now with Multimap from Live Search
#
Sorry! Hopefully just one more question!

I'm now trying to plot columns 3 and 6. I've tried:
...but this plots columns 4 and 5 too!


I've also tried:
But these don't produce the right results (instead, errors!)

Again, I'm sure it's a just a small (but important) detail that I'm missing, and I'd be very grateful if anyone could help me out.

Many thanks again,

Steve

________________________________
Date: Thu, 4 Sep 2008 13:52:03 -0300
From: wwwhsd at gmail.com
To: smurray444 at hotmail.com
Subject: Re: [R] Plotting using 'if' statements
CC: r-help at r-project.org

Use '&':

plot(January[January[,3]> 0 & January[,3] < 2, 3:4])
On Thu, Sep 4, 2008 at 1:47 PM, Steve Murray wrote:
Ah that's great, thank you very much.



As a follow-on, in the same format, how would I plot where column 3 is greater than 0 *but also less than 2*?



Once again, any help is much appreciated.





Thanks,



Steve



________________________________

Date: Thu, 4 Sep 2008 13:39:12 -0300

From: wwwhsd at gmail.com

To: smurray444 at hotmail.com

Subject: Re: [R] Plotting using 'if' statements

CC: r-help at r-project.org



Try this:



plot(January[January[,3]> 0, 3:4])
On Thu, Sep 4, 2008 at 1:28 PM, Steve Murray wrote:
Dear all,







I have a dataset of four columns, and I wish to plot (as a scatter graph) the values of the third column where the values are greater than zero, and the fourth column.







I tried doing this via the plot command itself, but got into a bit of a mess (resulting in errors!). My dataframe is called 'January':
Error: unexpected '>' in "plot(January[3(>"











After a few variations on this, I thought I'd try making a new object which includes all values from the third column of January>0 (to plot in a separate step) as follows:
No error here. However, when I display the 'values' of JanFilter, it shows that instead of keeping the numerical values, the above operation simply displays the results of the logical test:
Value



[1,]                       FALSE



[2,]                        TRUE



[3,]                        TRUE



[4,]                        TRUE



[5,]                        TRUE



[6,]                        TRUE











[[elided Hotmail spam]]







So my question is, how do I perform 'if' statements in order to filter out various parts of a dataset, for plotting on a graph.







Many thanks,







Steve







______________________________________________



R-help at r-project.org mailing list







PLEASE do read the posting guide http://www.R-project.org/posting-guide.html



and provide commented, minimal, self-contained, reproducible code.









--

Henrique Dallazuanna

Curitiba-Paran?-Brasil

25? 25' 40" S 49? 16' 22" O







_________________________________________________________________







--
Henrique Dallazuanna
Curitiba-Paran?-Brasil

25? 25' 40" S 49? 16' 22" O



_________________________________________________________________
Win New York holidays with Kellogg?s & Live Search
#
Thanks again for a very quick reply! It worked really well too!



_________________________________________________________________
Discover Bird's Eye View now with Multimap from Live Search