0

I have found seemingly correct solutions to my problem of creating a mixed legends with linetype and colour here and here. However my code still does not the expected and instead produces a legend where the linetype is not taken into account. My goal is to have my legend match my plot.

I have started with a simple scale_linetype_manual("",value = c(2,2,1,1,1)) and stopped at the attempt in the code below.

ggplot(data_norm_long, aes(x = as.integer(year), y = value, colour = variable, linetype = kat), group = "variable") +
    geom_point() +
    geom_line() +
    scale_color_manual("",
    breaks = c("LO_kat2","lean_kat2","hola_kat1","lean_kat1","LO_kat1"),
    values = c(LO_kat2 = "darkblue", lean_kat2 = "darkgreen", hola_kat1 = "darkred", lean_kat1 = "darkgreen", LO_kat1 = "darkblue"),
    labels = c("Label 1","Label 2","Label 3","Label 4","Label 5")) +
    scale_linetype_manual("",
                          breaks = c("LO_kat2","lean_kat2","hola_kat1","lean_kat1","LO_kat1"),
                          values = c("1" = "solid", "2" = "dashed"))

Plot:

Current plot (Apparently I'm not allowed to embed images.)

Mangobae
  • 13
  • 3
  • Can you add some of your data? try using `dput(head(data_norm_long))`. I suspect that you need to put a `labels = ` call inside the `scale_linetype_manual` call. – bob1 Nov 07 '18 at 16:29
  • This is the output of `dput(head(data_norm_long))`. `structure(list(year = c("1985", "1986", "1987", "1988", "1989", "1990"), variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L), class = "factor",.Label = c("hola_kat1", "lean_kat1", "LO_kat1", "lean_kat2", "LO_kat2")), value = c(0, 0, 0, 0, 0, 0), kat = c("1", "1", "1", "1", "1", "1")), .Names = c("year", "variable", "value", "kat"), class = c("data.table", "data.frame" ), row.names = c(NA, -6L), .internal.selfref = )` What kind of label do you think needs to be set? – Mangobae Nov 07 '18 at 16:51

0 Answers0