Hi:

As David originally noted, your dates are going to be read in as factors
with data.frame() unless you explicitly define them as Date objects first.
Here's one way to get the plot using a toy example (since you didn't provide
any data):

library(ggplot2)
dd
[1] "21/2/10" "30/3/10" "30/4/10" "30/5/10"
> class(dd)
[1] "character"
df <- data.frame(Date = as.Date(dd, format = '%d/%m/%y'),
                  mean = c(10, 12, 13, 11),
                    sd = c(2.5, 3, 4, 3))
> str(df)
'data.frame':   4 obs. of  3 variables:
 $ Date:Class 'Date'  num [1:4] 14661 14698 14729 14759
 $ mean: num  10 12 13 11
 $ sd  : num  2.5 3 4 3

g + geom_point(color = 'red', size = 2.5) +
     geom_line(color = 'blue', size = 1) +
     geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = 3)


This may not be what you expect, though. If you want the x-axis labels to be
the dates as you've written them, one approach is to convert Date to an
ordered factor:

df$fdate <- factor(dd, levels = dd)
h <- ggplot(df, aes(x = fdate, y = mean))
h + geom_point(color = 'red', size = 2.5) +
     geom_line(aes(group = 1), color = 'blue', size = 1) +
     geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = 0.3)

The aes(group = 1) bit in geom_line() is necessary to plot a line across the
levels of a factor. The width parameter in geom_errorbar() behaves
differently when x is a factor rather than a date. (Try width = 3 and see :)

To change the x scale tick marks while keeping Date as a Date object, use
scale_x_date() and add the code to the first plot's code chunk; I'll let you
decide how you want to display them. The on-line help page is at
http://had.co.nz/ggplot2/scale_date.html

HTH,
Dennis



On Wed, Oct 27, 2010 at 2:17 AM, ashz <ashz@walla.co.il> 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?
>
> Thanks.
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/ggplot-unwanted-sorted-X-values-tp3015099p3015099.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org 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.
>

	[[alternative HTML version deleted]]

