Hello, I am trying to plot time-series data with certain weeks highlighted 
using symbols.

require(ggplot2)

#plotting time series data
timescale <- seq(as.Date("01/01/09","%m/%d/%y"), length.out=12, by=7)
data.all <- data.frame(
    id = c(rep('111',12),rep('222',12),rep('333',12)),
    week=c(timescale,timescale,timescale),
    value=c(rnorm(12,15,3),rnorm(12,30,5),rnorm(12,20,5))
)

p <- ggplot(data.all, aes(x=week, y=value, group=id, colour=id)) + 
geom_line(size=1.05)

#adding indicators on each line
data.all$ind <- 
c(rep("",4),rep("2",2),rep("",4),rep("3",2),rep("",2),rep("2",4),rep("",3),rep("6",3),rep("",8),rep("1",4))

ind.uniq = setdiff(unique(data.all$ind),c(""))
names(ind.uniq) <- paste("ind", ind.uniq, sep="")
ind.df <- data.frame(lapply(ind.uniq, function(x) ifelse(data.all$ind==x, 
data.all$value, NA)))
ind.df <- cbind(data.all[,c("id","week")],ind.df)

How can I add markers based on the data in ind.df? In the above example, there 
are four indicators 1,2,3 and 6.  I'd like to be able to show each using a 
different shape (circle, triangle, square, cross). Additionally, I'd like to 
use the same colors for the markers as the lines they are plotted on.

Thanks.

______________________________________________
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.

Reply via email to