I have the following code:
structure(list(Type = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("Complex-valued", "Magnitude-only"), class = "factor"),
AR.coef = c(0, 0.025, 0.05, 0.075, 0.1, 0.125, 0.15, 0.175,
0.2, 0.225, 0.25, 0.275, 0.3, 0, 0.025, 0.05, 0.075, 0.1,
0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3), variable = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "p=phat", class = "factor"),
value = c(0.978520704704333, 0.97587336999776, 0.973265254008069,
0.968200928906036, 0.964398292699414, 0.958921339792823,
0.954257350293665, 0.949424417504299, 0.942783668590964,
0.937194487113138, 0.931500996099189, 0.925212095505999,
0.918554141700981, 0.978840106896505, 0.976226910306292,
0.973587133603869, 0.968631836203812, 0.965199812495933,
0.960256158986167, 0.956236529101204, 0.951525171907093,
0.944964615583583, 0.938993495998045, 0.933391264497136,
0.926722511197902, 0.920070531126096)), row.names = c(NA,
-26L), .Names = c("Type", "AR.coef", "variable", "value"), class = "data.frame")
>ere
which contains the AR.df dataframe. Now I want to plot using the same variable for linetype and colour but I am getting two legends, I would like one legend but the lines with different colors and linetypes as apt. Here is my code:
ggplot(AR.df, aes(x = AR.coef, y = value, linetype = Type, colour = Type)) +
geom_line(size=1.25) + xlab("AR(1) coefficient") +
ylab("Proportion") + theme_bw() +
theme(legend.justification=c(1,-0.2),
legend.position=c(0.45,0.5),
legend.text=element_text(size=10),
legend.title=element_text(size=10),
axis.title.x=element_text(size=10),
axis.title.y=element_text(size = 10),
legend.key = element_blank(),
legend.background = element_rect(color="black",size = 0.1)) +
scale_colour_manual(values=cbPalette, name="Analysis Type") +
scale_linetype_manual(values=c("solid", "dashed")) +
theme(legend.key.width=unit(3,"line"))
which gives the following plot with two legends:
How do I get rid of the first legend box and get the legend in the second box to also have the linetype?
name
toscale_linetype_manual
. – Roland