I have the following data set:
dput(ByStationR90Data[1:5,])
structure(list(Station = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("125",
"137"), class = "factor"), SampleDate = structure(c(13216, 13313,
13342, 13397, 13488), class = "Date"), Date = c(20060309, 20060614,
20060713, 20060906, 20061206), FecalColiform = c(2, 2, 79, 2,
2), Flog = c(0.301029995663981, 0.301029995663981, 1.89762709129044,
0.301029995663981, 0.301029995663981), Avlog = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), STD = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), F90 = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_)), .Names = c("Station", "SampleDate", "Date", "FecalColiform",
"Flog", "Avlog", "STD", "F90"), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -5L), vars = list(Station), drop = TRUE, indices = list(
0:4), group_sizes = 5L, biggest_group_size = 5L, labels = structure(list(
Station = structure(1L, .Label = c("125", "137"), class = "factor")), class = "data.frame", row.names = c(NA,
-1L), vars = list(Station), drop = TRUE, .Names = "Station"))
I have created a graph of the rolling 90th percentiles of fecal coliform for two marine water sampling stations. I want to demonstrate the the range of values that put the station in a "Threatened" status (30-43). I almost have it! I have used geom_rect to create a box and made it red, with a label. I just want to make it somewhat transparent because the red is overwhelming as is. Every time I add alpha to the equation it does not change the red color and instead adds a weird box above the legend. Reading through other problems with alpha, I have tried moving it to different places, and moved parentheses around and I either get errors or something that looks worse.
My code:
ThreatSt <- ggplot(subset(ByStationR90Data, Station %in% c("125", "137"))) +
geom_hline(yintercept = 43, color = "red", linetype="dashed", size = .7, show_guide = TRUE) +
geom_rect(mapping = aes(xmin = as.Date(c('2010-10-01')), xmax = as.Date(c('2016-04-01')),
ymax = 43, ymin = 30, fill = "Threatened Zone", show_guide = FALSE)) +
scale_fill_manual("", breaks = "Threatened Zone", values = "red", alpha = 0.5)+
geom_line(aes(SampleDate, F90, group = Station, colour = Station), size=1.5) +
scale_color_brewer(palette = "Dark2")
ThreatSt <- ThreatSt +
theme_bw() +
ggtitle("Fecal Coliform Rolling 90th Percentiles for Stations 125 and 137
\n Hood Canal #3 Growing Area") +
ylab("Fecal Coliform (fc/100 ml)") +
annotate(geom="text", x=as.Date("2015-01-01"), y=45,label="NSSP Limit", color="red") +
scale_y_continuous(breaks=seq(0,100,10), limits = c(10,60)) +
scale_x_date(
limits = as.Date(c('2011-01-01', '2016-01-01')),
labels=(c("2011", "2012", "2013", "2014", "2015", "2016")))
Any insight and/or help is appreciated. Thanks!
alpha = 0.5
to thegeom_rect
layer. It's an aesthetic and should be in the geom. – joranshow_guide
(show.legend
in ggplot2 2.0.0) should be outside of theaes
mapping ingeom_rect
. – aosmithgeom_rect(mapping = aes(xmin = as.Date(c('2010-10-01')), xmax = as.Date(c('2016-04-01')), ymax = 43, ymin = 30, fill = "Threatened Zone"), alpha = .5, show_guide = FALSE)
– aosmith