+3 votes
in Programming Languages by (60.0k points)

I am using ggplot for generating a plot. When I display the legend, it shows the title of the legend too. How can I remove the title of the legend from my plot?

Here is my code:

p1 <- ggplot(ndf, aes(x=xvals, y=yvals, fill = category, colour = category)) +

        geom_line() +

        scale_color_manual(values = c('black', 'red', 'blue', '#4DAC26')) +

        labs(x = "class probability", 

             y = "pdf" 

             ) +

        theme_bw() +

        theme(legend.position = c(.99, .99))

1 Answer

+1 vote
by (354k points)
selected by
 
Best answer

You need to add legend.title=element_blank() to the theme to remove the title of the legend.

Change your code as follows:

p1 <- ggplot(ndf, aes(x=xvals, y=yvals, fill = category, colour = category)) +
        geom_line() +
        scale_color_manual(values = c('black', 'red', 'blue', '#4DAC26')) +
        labs(x = "class probability",
             y = "pdf"
             ) +
        theme_bw() +
        theme(legend.position = c(.99, .99), legend.title=element_blank())

Related questions

+3 votes
1 answer
+3 votes
1 answer
+1 vote
1 answer
+1 vote
1 answer
+2 votes
1 answer

...