With ggplot2, I have learned to rename the X-Axis, the Y-Axis and the individual legends. However, I also want to rename the legend values.
As an example, for simplicity I have used 0 for male and 1 for female in a dataset, and when I display it and map gender to an aesthetic, I don't want the legend to read 0 or 1 for the data values, but male and female.
Or, in this example below, instead of "4", "f" and "r" using "4 wheel drive", "front wheel drive", "rear wheel drive" would make the graph much easier to understand.
library(tidyverse)
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy, color = drv)) + labs(x = "Engine Size (Liters)", y = "Fuel Efficiency (Miles per Gallon)", color = "Drive")
- One option would be to open the Excel file and change all the 0s and 1s in the specific column to "male" and "female".
- Another option would be to rename the values within R, but I have absolutely no idea how to do this. I'm very new to R.
What I'm hoping for is a simple way to rename the values displayed in the legend.


