I am trying to plot several different columns against the same x using ggplot. I have produced a plot with the lines as required, but can't work out how to add a legend linking each column title to the line colour shown in ggplot for that line.
My plotting code is:
#Plots Ceff, C2d and C3d vs log(freq)
ggplot(plotting,
mapping = aes(x = lfreq,y = Ceff))+
geom_line()+
geom_line(mapping = aes(x = lfreq ,y = C2D ), color = "green", show.legend = TRUE)+
geom_line(mapping = aes(x = lfreq, y = C3D), color = "blue")+
geom_line(mapping = aes(x = lfreq, y = Clim), color = "red")+
geom_line(mapping = aes(x = lfreq, y = K), color = "purple")+
ylim(c(0.00001, 0.0005))+
xlim(c(-1, 5))+
xlab("log(W)")+
ylab("C (F/cm2)")
I have tried to add:
scale_shape_discrete(name = "Capacitance",
breaks = c("Ceff", "C2D", "C3D", "Clim", "K"),
labels = c("Ceff", "C2D", "C3D", "Clim", "K"))
to my ggplot, and also add show.legend = "True"
to each geom_line()
but neither has had any effect. Apologies - I can see there are lot's of answers about this topic but I can't work out how to apply this to my situation.