[R] Interesting Behavior in plot()

Clint Bowman clint at ecy.wa.gov
Tue Mar 30 00:47:57 CEST 2004


Right on.  The convenience of slurping up data with read.table() and the 
nearly expected plot caused me to overlook that V2 was read in as a 
factor.  I also had quite a few NAs which may have contributed to the 
problem.

Thanks

On Mon, 29 Mar 2004, Duncan Murdoch wrote:

> On Mon, 29 Mar 2004 14:06:36 -0800 (PST), Clint Bowman
> <clint at ecy.wa.gov> wrote :
> 
> >I have a 2 by 226200 table, conveniently read in by read.table(), which
> >exhibits some strange behavior when plotted by plot(V1,V2).  The general
> >pattern for the range of windspeeds, [0<V1<50] is as expected -- the wind
> >gust falls in the interval [V1<V2<65] except for certain values of V2.  
> >For V2 == c(15,26,37,48,59), the V2 values are positioned at one-tenth of 
> >the V1 (i.e., as if I had issued the command plot(0.1*V1,V2) for just 
> >those values of V2 -- see attached plot, test.png).  The only other values 
> >of V2 in the range, 4 and 70, also seem to be affected but aren't well 
> >enough represented to show up clearly on the plot.
> >
> >However, if I plot(ws$V1[ws$V2==48],ws$V2[ws$V2==48]), I see the second 
> >attachment, test2.png, which confirms that the wind speed (V1) really 
> >should be positioned where one would expect.  I haven't seen any messages 
> >covering this behaviour and so am looking for an explanation.
> 
> I can't quite see how it would generate the symptoms you saw, but a
> common source of oddities is that data is read as factors rather than
> as numeric values.  You can see the difference using the str()
> function, e.g.
> 
> > str(x)
>  num [1:10] -0.4897  0.6804  0.6979 -0.1203 -0.0428 ...
> > str(as.factor(x))
>  Factor w/ 10 levels "-1.65972758..",..: 4 7 8 5 6 9 2 10 3 1
> 
> I'd check your V1 and V2.
> 
> Duncan Murdoch
> 

-- 
Clint Bowman			INTERNET:	clint at ecy.wa.gov
Air Quality Modeler		INTERNET:	clint at math.utah.edu
Department of Ecology		VOICE:		(360) 407-6815
PO Box 47600			FAX:		(360) 407-7534
Olympia, WA 98504-7600




More information about the R-help mailing list