Hello all and thanks in advance,
I am trying to have my legend show filled shapes, opposed to simply outlining with color (shown below):
My code is as follows:
p.ch4 <- ggplot(ch4.data, aes(x=date, y=value, group = type,
fill=type, color=type)) +
geom_line() +
geom_point(aes(shape=type), color = "black", size =4) +
geom_point(aes(shape=type, color=type), size=3) +
scale_shape_manual(values = c(21:24)) +
scale_fill_manual(values = c("darkorchid3","indianred3","dodgerblue3")) +
scale_color_manual(values = c("darkorchid3","indianred3","dodgerblue3")) +
annotate("rect", xmin=as.POSIXct("2017-11-09"), xmax=as.POSIXct("2018-04-09"),ymin=0,ymax=75,alpha=.25) +
scale_y_continuous(sec.axis = sec_axis(~., name = expression(paste('Methane (', mu, 'M)')))) +
labs(y = expression(paste('Methane (', mu, 'M)')), x = "", color = "", shape = "") +
theme_linedraw(base_size = 18) +
#theme(legend.position = "none") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
strip.text = element_text(face = "bold")) +
theme(axis.text = element_text(angle = 45, hjust = 1))
print(p.ch4)
I realize I have done a lot of work regarding datapoint colors, outlines, and shapes, and I wondered if therein lies my issue?
For reproducibility, here is my dataset "ch4.data":
> dput(ch4.data)
structure(list(type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("SWI",
"4cm", "12cm"), class = "factor"), date = structure(c(1537167600,
1535266800, 1533279600, 1531292400, 1529305200, 1527318000, 1526713200,
1527231600, 1525762800, 1524294000, 1522825200, 1521356400, 1516089600,
1511596800, 1509606000, 1537340400, 1534575600, 1531119600, 1530255600,
1527663600, 1525071600, 1517212800, 1513756800, 1510300800, 1537167600,
1535094000, 1533020400, 1530946800, 1528873200, 1528441200, 1526713200,
1524898800, 1522393200, 1519545600, 1516435200, 1514361600, 1510992000
), class = c("POSIXct", "POSIXt"), tzone = ""), value = c(52.43,
40.37, 12.92, 5.12, 4.93, 2.4, 1.97, 3.07, 5.7, 3.56, 2.74, 0.67,
0.78, 0.48, 0.7, 0.3, 0.21, 4.11, 1.54, 4.86, 7.42, 3.62, 0.81,
0.37, 6.2, 9.14, 34.11, 57.83, 63.02, 63.56, 54.13, 42.92, 32.59,
23.23, 9.97, 5.62, 0.52), geochem = c("ch4", "ch4", "ch4", "ch4",
"ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4",
"ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4",
"ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4", "ch4",
"ch4", "ch4", "ch4", "ch4", "ch4", "ch4")), row.names = c(NA,
-37L), class = "data.frame")
Thank you!

