[R] Plot, lines and disordered x and y

hadley wickham h.wickham at gmail.com
Fri Jan 23 20:43:05 CET 2009


>>
>> This is of course minor  (actually asymptotically, no annoyance at
>> all). I am just mentioning it for 'completness' sake and because a
>> divinely ideal plotting function should cope with data given in any
>> order.
>>
>
>  The problem here is that a divinely ideal plotting function
> for other people would allow data to be in any order, and plot
> it respecting that order, rather than automatically assuming
> it should be sorted.  The less intrusive alternative, allowing
> a "sorted" flag to plot, is an example of "feature creep" --
> once we succumb to the temptation to add this, there are a million
> other special cases that people want, and plot ends up with
> a million options (and 2^(10^6) interactions among the options
> that lead to surprising outcomes).

Or you can adopt a decent theory of statistical graphics where the
components are orthogonal and don't interact in surprising ways and
end up with something like ggplot2.

>  While it seems like a pain,
> it really makes more sense in the long run to require users
> to rearrange their data.  Here's a straightforward way:
>
>
> x <- c(1,-1,2,-2,3,-3,4,-4,5,-5)
> y <- c(1,0,2,0,3,0,4,0,5,0)
> plot(x,y,type='l')   #bad
> plot(x,y) # this is how it should look like

or

library(ggplot2)
qplot(x, y, geom="line")
# vs
qplot(x, y, geom="path")

Hadley


-- 
http://had.co.nz/




More information about the R-help mailing list