r - Remove lines from color and fill legends -


i have plot 3 different legends: 1 linetype, 1 color, , 1 fill. in color , fill legends there lines wish remove, how?

here example code:

# data hline_df <- data.frame(name = c('a', 'b'), y = c(1, 2)) df <- data.frame(x = c(1, 2), y = c(0.5, 1.5), con = c('a', 'b'), col = c('d', 'e'))  # plot ggplot(df, aes(x, y, fill = con)) +   geom_bar(stat = 'identity') +    geom_point(aes(color = col)) +   geom_hline(data = hline_df, aes(yintercept = y, linetype = name),              color = 'red', show_guide = true) 

enter image description here

i "name" guide both red lines, fine.
"col" guide has red lines crossing dots, want remove them!
"con" guide has red lines should removed.

i modify parts of legend

guides(fill = guide_legend(override.aes = list(colour = null)),        color = guide_legend(override.aes = list(colour = null))) 

this removes colour, lines still there.

thanks in advance!

you may set linetype = 0 or "blank" (on different linetypes here) filland color guides in override.aes call.

also note moved fill aes 'top level' in ggplot geom_bar.

ggplot(df, aes(x, y)) +   geom_bar(aes(fill = con), stat = 'identity') +    geom_point(aes(color = col)) +   geom_hline(data = hline_df, aes(yintercept = y, linetype = name), color = 'red', show_guide = true) +   guides(fill = guide_legend(override.aes = list(linetype = 0)),          color = guide_legend(override.aes = list(linetype = 0))) 

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 -