I'm seeking some assistance with modifying the legend in my plot using the data below.
dput(df)
structure(list(Week.Number = 1:16, Dist.18 = c(5331.83038, 14084.08602,
12219.423585, 14406.407445, 5032.74848, 10820.094835, 16935.546075,
15387.590625, 16195.21247, 20012.09881, 14057.385255, 5127.14891,
16241.98523, 12793.21837, 10526.785375, 6014.43878), HIR.18 = c(1098.56001,
4093.010015, 4372.84498, 4074.22002, 709.70499, 2460.04999, 5037.77501,
5521.029965, 5463.410025, 6761.34502, 3953.20997, 1189.89, 3663.69006,
2333.005005, 2289.38001, 1069.740005), V6.18 = c(0, 40.77, 63.505,
112.63, 52.395, 56.795, 211.115, 75.52, 215.059995, 121.725,
57.64, 15.35, 140.34, 15.615, 85.66, 31.815), Dist.17 = c(11820.06249,
18123.592835, 14560.30914, 17193.56009, 7733.785765, 15536.659865,
8694.08218, 19569.060865, 14153.71578, 18498.63446, 16452.63166,
16820.32351, 9242.407875, 8857.62039, 2371.09375, 10340.258575
), HIR.17 = c(2693.425035, 4971.474985, 4521.895065, 5561.53997,
1759.31996, 3924.48, 1893.485, 5571.700035, 3239.94503, 4773.02004,
5927.174995, 4537.58996, 1618.49499, 2771.84002, 284.56, 2181.749995
), V6.17 = c(15.58, 38.355, 240.355, 354.059995, 1.76, 187.575,
93.495, 184.925, 88.27, 165.08, 231.075, 171.09, 32.55, 93.88,
0, 56.19)), .Names = c("Week.Number", "Dist.18", "HIR.18", "V6.18",
"Dist.17", "HIR.17", "V6.17"), row.names = c(NA, -16L), class = "data.frame")
This code generates the plot.
plot <- ggplot(df, aes(x = Week.Number, y = Dist.18, fill = "2018")) +
geom_col() +
geom_line(aes(x = Week.Number, y = Dist.17, fill = "2017"), size = 0.75) +
geom_point(aes(x = Week.Number, y = Dist.17), size = 0.75) +
scale_fill_manual("color", values = c("2017" = "black", "2018" = "blue")) +
scale_x_continuous(breaks = c(1:16)) +
ylab("Dist") +
theme_classic() +
theme(plot.title = element_text(face = "bold"),
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"))
I wish to change the title of the legend to "Season" and modify the key. I'm wondering if it's possible to have two different points in the key. For example, a solid blue square for the label 2018 and a black line for 2017, representing each geom in the plot.
Also, i used fill =
in the aes()
argument to generate a legend in the first instance. This seems to work, but not sure if it's best practice or not.
Hope I've provided enough information. Any help will be greatly appreciated. Thank you.