Hi: Here's a ggplot2 version of your graph. Since you didn't include the dates, I had to make them up, and it may have some consequence with respect to your times because yours don't appear to be exactly equally spaced.
I created two data frames - an 'original' one that contains both series in separate columns, and another that 'melts' the original data frame by stacking the two series horizontally with a created factor that holds the variable names. Notice that I assigned the names of the two series to Series4 and Series6 in the original data frame to correspond with the names on the plot. library(ggplot2) dd <- data.frame(tm = seq(as.Date('2002-1-1'), by = 'month', length = 50), Series4 = x1, Series6 = x2) dm <- melt(dd, id = 'tm') dd <- transform(dd, ylo = pmin(Series4, Series6), yup = pmax(Series4, Series6)) The melted data, dm, is useful for plotting the two series and associating a color aesthetic to the different series; we use it to generate the initial part of the plot, the two series themselves. 'variable' is a factor variable whose levels are the variable names (which map to the legend) and 'values' is a numeric variable containing the values of the two series. g <- ggplot(data = dm, aes(x = tm)) g + geom_line(aes(y = value, colour = variable), size = 1.2) + scale_colour_manual("", values = c('Series4' = 'yellow', 'Series6' = 'red')) + theme_bw() + ylim(4, 12) + geom_linerange(data = dd, aes(x = tm, ymin = ylo, ymax = yup), size = 0.8) + opts(panel.grid.major = theme_blank()) + opts(panel.grid.minor = theme_blank()) + geom_hline(yintercept = c(4, 6, 8, 10, 12), size = 1, alpha = 0.1) + scale_x_date(major = '2 months', format = '%b-%Y') + opts(axis.text.x = theme_text(angle = 90, hjust = 1, vjust = 0.5, size = 9)) scale_colour_manual() allows specification of one's own colors rather than ggplot2's defaults. The initial pair of double quotes gets rid of the legend label - if you leave it off, it will use the header 'variable'. You can always substitute in another legend header if you wish. The vertical lines connecting the series at each date is where the work is required. ylo and yup in data frame dd represent the min and max values of the series at each date, respectively, produced by the pmin() and pmax() functions. ggplot2's geom_linerange() needs these variables to represent the lower and upper limits of the line segments at each x value (date), which is why the data frame used in geom_linerange() is dd rather than dm. The size parameter in geom_line() and geom_linerange() corresponds to line thickness. The first two opts() statements get rid of the default grid lines; geom_hline() provides the substitutes. The scale_x_date() code basically labels every other date with some additional options to pretty up the appearance of the labels. HTH, Dennis On Tue, Aug 24, 2010 at 2:40 PM, abotaha <yaseen0...@gmail.com> wrote: > > Thanks a lot for the nice explanation. however, you mention that it will be > nicer if there is data. yes you are right it be very kind of you if you > include a simple example. where my data are: > > x1<-c(11.5,9.38,9.3,9.8,9,9.06,9.42,8.8,9.05,8.14,8.2,7.59,6.92,6.47,7.12, > > 7.47,6.81,8.41,9.64,9.62,9.2,8.92,8,7.6,7.6,7.19,6.94,6.91,7,7.25,6.6,7.18,7.78, > > 7.37,7.29,6.71,7.05,6.69,6.05,6.38,6.18,7.67,7.34,7.13,6.95,6.8,6.45,6.81,6.27,6.35) > > > x2<-c(11.5,8.959535,9.728104,9.609262,8.755494,9.221545,8.244458,7.63944,7.92052,7.690449,7.853247, > > 7.239616,6.609007,5.92946,6.47822,5.906936,6.966004,8.630517,9.506582,9.57479,9.236638,9.581875,8.838992,8.368731,8.608884,7.998023,7.918123,7.832322,7.930177,7.479222,6.866978,7.454062,8.206185,7.344037,7.059774,6.547646,7.005803,6.623987,5.992691,6.313481,6.194613,6.224266,7.084932,6.568976,6.43866,5.70081,6.7593,6.6929,6.46806,5.964816) > > regards, > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Plot-bar-lines-like-excel-tp2337089p2337394.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]] ______________________________________________ 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.