Fwd: Custom legend in ggplot - stat_summary shape and geom_bar fill

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Custom legend in ggplot - stat_summary shape and geom_bar fill

JamesDare
Hi Everyone,

I am spending far to much time on this problem.  Every post I read gets me
closer to a solution,  but I am still not quite there.

I am trying to create a bar plot similar to the one below:

<http://r.789695.n4.nabble.com/file/t124289/Desired_Output.png>

My code is as follows:

q92 <- function(x) {quantile(x,probs=0.92,na.rm = TRUE)}

ggplot(River_Df, aes(x= reorder(Name, ECOLI, FUN = q92, order=TRUE),
y=ECOLI))+
  geom_bar(stat="summary",fun.y="median",aes(colour = "Median"),
fill="#2eb82e")+
  stat_summary(fun.y=q92, geom ="point",size=3, shape=18,aes(colour ="95th
Percentile"),show_guide = FALSE)+
  theme(axis.text.x = element_text(angle = 90, hjust = 1))+
  xlab(paste("Monitored River Sites
",format(min(River_Df$Time),"%Y"),"-",format(max(River_Df$Time),"%Y"),sep=""))+
  ylab("E. coli (cfu/100mL)")

As you can see, I end up with two legend items, '95th Percentile' and
'Median'.  However, I would like the '95th Percentile' item to be a darkred
diamond with no background.

Any ideas how to do this?  The dataset is attached below:

Datafile.csv <http://r.789695.n4.nabble.com/file/t124289/Datafile.csv>

Thanks in advance for your help.

James

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.