How to change the text in the colour legend of ggplot2

Jorge Martínez

I have this code:

ggplot(databoth, aes(withxstep)) + 
       geom_point(aes(y = withnassoc, colour = "withnassoc"), size = 2.8) + 
       geom_point(aes(y = withoutnassoc, colour = "withoutnassoc"), size = 1 ) +
       labs(colour = "Legend") +
       labs(x = "Time") +
       labs(y = "N associations")

How do I modify the withnassoc and the withoutnassoc? I would like it to be "With Activities" and "Without activities".

M--

This should answer your question:

ggplot(databoth, aes(withxstep)) + 
       geom_point(aes(y = withnassoc, colour = "withnassoc"), size = 2.8) + 
       geom_point(aes(y = withoutnassoc, colour = "withoutnassoc"), size = 1 ) +
              labs(colour = "Legend", x = "Time", y = "N associations") +
              scale_color_manual(values = c("red", "blue"), 
                                 labels = c("With Activities", "Without activities"))

For this example data-set:

exampledata <- structure(list(withxstep = structure(c(4L, 3L, 2L, 1L), 
.Label = c("2017-06-27", "2017-06-28", "2017-06-29", "2017-06-30"), class = "factor"), 
withnassoc = c(1, 2, 3, 4), withoutnassoc = c(5, 6, 7, 8)), .Names = c("withxstep", 
"withnassoc", "withoutnassoc"), class = "data.frame", row.names = c(NA,-4L))

This would be the plot:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change background colour of legend in ggplot2?

How to change the text colour of font in legend?

How to change legend title and key order and colour to a multi-stacked barplot in R with ggplot2

Is it possible to change the colour of legend elements in ggplot2?

change colour of legend box in ggplot

Legend Trouble in R- how to change legend text in ggplot2

How to adjust legend for a colour-shape combiation in ggplot2?

How to change colour and position of geom_text for just one bar in a barplot in ggplot2 (R)?

How do I change the background colour of a legend box in ggplot?

ggplot2: how to change the order of a legend

How to change items in a ggplot2 legend?

How to align legend symbol with wrapped legend text on ggplot2

Text colour does not match legend using geom_text in ggplot2

How to change colour for barplot in ggplot2 using viridis package?

How to change colour and add legend on Laplacian plot?

How to change a density curve without changing the legend in ggplot2?

How to change scientific notation on legend labels in ggplot2

How can I change the legend linetype in ggplot2?

How to change the order of the legend of geom_rects in a ggplot2?

How to change angle of line in customized legend in ggplot2

How to change legend label in "theme" argument in ggplot2?

In ggplot2, how to change the legend labels but leave the colors unchanged?

How to change ggplot2 legend to include negative and positive values?

How can I change the legend labels in R (ggplot2)

How to change legend type with ggplot2 in R?

How to manually change the ggplot2 legend to include vlines?

How to change orientation of each item in a ggplot2 legend?

How to change legend shapes in R using ggplot and scale_colour_brewer()

How to change the colour of the lines in ggplot