[R] ggplot - unwanted sorted X values

David Winsemius dwinsemius at comcast.net
Wed Oct 27 16:47:20 CEST 2010


On Oct 27, 2010, at 5:17 AM, ashz wrote:

>
> Hi,
>
> I have this script:
>
> dat <- data.frame(X = halistat$Date,Y1 = halistat$avg,Y2 = halistat 
> $stdev)
> ggplot(data = dat, aes(x = X, y = Y1, ymin = Y1 - Y2, ymax = Y1 +  
> Y2)) +
>  geom_point() + # points at the means
>  geom_line() + # if you want lines between pints
>  geom_errorbar() # error bars, Y1 - Y2 and Y1 + Y2
>
>
> halistat$Date values:
> 29/1/10
> 21/2/10
> 30/3/10
> 30/4/10
> 30/5/10
>
>
> In the resulted plot the X values are sorted, how can I cancel it?

Those X values are most likely not Date class but rather factors and  
sorted alphabetically as is typically done at time of factor creation.  
You probably need to work with factor levels. (All guesswork in the  
absence of a reproducible example.)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list