Do you have some sample data that we could use to play around with?-B
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Do you have some sample data that we could use to play around with?-B
On Thu, Dec 30, 2010 at 14:06, simeond <simeond...@gmail.com> wrote:
It's not perfect but...adGraph <- function(data,period, indicator1, indicator2,...){
df <- melt(data,id=period,measure=c(indicator1,indicator2))
df$panel <- "ind1"
df[df$variable %in% indicator2,"panel"] <- "ind2"
df$panel <- factor(df$panel,levels=c("ind1","ind2"),ordered=T)
print(head(df))
p<-ggplot(df,aes_string(x = "date", y = "value")) +
geom_line() +
geom_line(subset=.(panel=="ind1"),aes_string(colour="factor(variable)"),size=1.2)+
geom_smooth(subset=.(panel=="ind1"),size=1)+
geom_area(subset=.(panel=="ind2"),aes_string(fill="factor(variable)"),alpha=0.6)+
scale_y_continuous("",formatter=comma)+
scale_colour_grey("Ind1") +
scale_fill_brewer("Ind2",palette="Set1")+
facet_grid(panel ~. ,heights=c(2,1),scales="free")
print(p)
}
adGraph(data=economics, period="date", indicator1="unemploy", indicator2=c("psavert", "uempmed"))
Seems to work. I hope that helps you get to where you're going.
Brandon
On Thu, Dec 30, 2010 at 18:24, Brandon Hurr <brando...@gmail.com> wrote:
Simeon,I went through and followed all of your code outside of the function. The problems came up when you used "df$panel" or df$variable to tell ggplot what to plot. I believe that anywhere you are passing a variable (say from a function) then you need to put that inside of aes_string(). I could be wrong, but I think that is the problem.BrandonOn Thu, Dec 30, 2010 at 17:45, simeon duckworth <simeond...@gmail.com> wrote:
hi brandon,
thanks ...'aes_string' is already in there. if i explicitly declare "x=" & "y=", i get the warning that 'df$variable is of type closure and is not subsettable'. i suspect the issue is more how to get the subetting variable ("panel") to be evaluated in the right environment.
very grateful for any further thoughts..