I need the legend in my plot to reflect the color and linetype in the graph. My code is below.
tibble::tribble(
~variable, ~value, ~bin, ~ci,
"Advanced HS", 302.097396142857, "FFD", 21.2978862705524,
"Beginner HS", 394.264259996296, "FFD", 28.8027249069651,
"Children", 379.642674397368, "FFD", 18.1482664147856,
"Adults", 217.875580083333, "FFD", 2.38006646944708,
"Advanced HS", 305.244904223809, "SFD", 15.5487255740993,
"Beginner HS", 350.108404085185, "SFD", 28.6379128865829,
"Children", 358.329722218421, "SFD", 12.6900032541364,
"Adults", 228.522062813542, "SFD", 2.73230976574123,
"Advanced HS", 484.181295019048, "GD", 33.9933197272878,
"Beginner HS", 960.745730144444, "GD", 55.8118108393556,
"Children", 676.158669963158, "GD", 44.238558449867,
"Adults", 259.127882341667, "GD", 4.30648424130776,
"Advanced HS", 702.136573061905, "TT", 47.0883793662974,
"Beginner HS", 1541.69112013704, "TT", 84.3091269009313,
"Children", 976.54035988421, "TT", 60.0584639291095,
"Adults", 318.08245218125, "TT", 7.99092674935576
)
mytheme <- theme_bw() + theme(axis.title = element_text(size = rel(2)),
strip.text = element_text(size = rel(2)),
legend.position = "bottom",
legend.key = element_blank(),
text = element_text(size = 28),
legend.text = element_text(size = 28),
plot.margin = margin(20, 20, 20, 20),
axis.text.x = element_text(hjust = 0.5, vjust = 0.5, size = 35),
axis.text.y = element_text(hjust = 0.5, vjust = 0.5, size = 35),
strip.background = element_rect(fill = 'gray96'))
tiff("r.tiff", units="in", width=10, height=7, res=300)
ggplot(data = Figure_1) +
mytheme + scale_y_continuous(breaks = seq(0,2000, 500))+
aes(x = bin, y = value, group = variable, color = variable) + scale_x_discrete(limits = c ("FFD","SFD", "GD", "TT")) +
geom_errorbar(aes(ymin=value-ci, ymax=value+ci), width=.1) +
geom_line(aes(group=variable, linetype = variable), size =2) + scale_linetype_manual(values=c("solid", "longdash", "dotdash", "dotted")) +
theme(legend.title = element_blank()) +
guides(col = guide_legend(reverse = FALSE, override.aes = list(size=6))) +
xlab("") +
ylab("Duration (ms)")
dev.off()