r - Duplicate legend with geom_vline() in ggplot -


i want create graphic:

aux_graf = structure(list(lines = structure(c(2l, 2l, 1l, 3l), .label = c("h0",  "ic", "median"), class = "factor"), values = c(21.19755, 23.06978,  24, 22.13366)), .names = c("lines", "values"), row.names = c(na,  -4l), class = "data.frame")  dadosgraf = structure(list(dados = c(18.7997, 20.5035, 18.6214, 19.9192,  21.117, 20.8353, 17.527, 17.078, 17.6197, 21.4255, 18.7545, 19.2026,  18.4187, 20.7641, 21.0553, 17.5905, 18.7561, 18.9772, 20.3084,  18.8988, 19.1688, 19.2898, 22.059, 18.5854, 17.8896, 21.1609,  26.1371, 21.4737, 30.9934, 22.8421, 24.4133, 20.4137, 25.5475,  21.8791, 22.6706, 24.7531, 25.7219, 22.6389, 26.2308, 26.7998,  28.4708, 26.9941, 25.1489, 24.6179, 27.0194, 25.0589, 22.1119,  20.3069, 23.6758, 27.1201, 29.6136, 25.9948, 18.223, 23.7336,  22.4208), y2 = 1:55), .names = c("dados", "y2"), class = "data.frame", row.names = c(na,  -55l))  gp2 <- ggplot(data = aux_graf)+        geom_vline(aes(xintercept = values, colour=lines, linetype=lines), show_guide=true)+        geom_point(data = dadosgraf, aes(x = dados, y=y2), size=3.2, shape=21, colour = 'black', fill = 'grey')+        theme_bw() 

enter image description here

now, want change labels, colour , linetype, when do, adds legend , don't know why.

gp2 + scale_color_manual(name = '', labels = c(ic = 'limites i.c.', median = 'mediana', h0 = 'hipotese nula'), values = c(ic = 'red', median = 'black',h0 = 'grey40'))     + scale_linetype_manual(values=c(ic = 'dashed', median = 'solid',h0 = 'dotted')) 

enter image description here

any help? thanks!

you can use override.aes in combination hiding linetype legend. with:

gp2 +    scale_color_manual(name = '',                       labels = c(ic = 'limites i.c.', median = 'mediana', h0 = 'hipotese nula'),                      values = c(ic = 'red', median = 'black',h0 = 'grey40')) +   guides(color = guide_legend(override.aes = list(linetype = c('dotted', 'dashed', 'solid'))),          linetype = false) 

you this: enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -