Hi:
Try this:
Your ind.df didn't include the values, so I redefined it such that it
contained all of
the data in data.all plus the indicators you set up in ind.df.
ind.df <- cbind(data.all[,1:3],ind.df)
# Using this ind.df as the data frame, set up the indicators so that all you
# need to do is call geom_point on each indicator, with its desired plotting
# character (pch), on top of the base plot p:
p <- ggplot(ind.df, aes(x=week, y=value, group=id, colour=id)) +
geom_line(size=1.05)
p + geom_point(aes(x = week, y = ind1, colour = id), shape = 1, size = 3) +
geom_point(aes(x = week, y = ind2, colour = id), shape = 2, size = 3) +
geom_point(aes(x = week, y = ind3, colour = id), shape = 22, size = 3) +
geom_point(aes(x = week, y = ind6, colour = id), shape = 4, size = 3)
Since this question properly belongs on the ggplot2 list, it is being cc'ed
there as well.
HTH,
Dennis
On Mon, Feb 1, 2010 at 6:06 PM, Chuck White <chuckwhite8@charter.net>
wrote:
> 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.
>
[[alternative HTML version deleted]]