Reputation: 52860
I use
geom_point(aes(colour = factor(ClusterID)))
but I want to get ClusterID
visible without the word factor
.
How can I modify the legend title in ggplot2?
Upvotes: 1
Views: 71
Reputation: 33802
Better to do the factor conversion before plotting. For example using dplyr
, assuming data frame mydata
and variables x, y
:
library(dplyr)
mydata %>%
mutate(ClusterID = factor(ClusterID)) %>%
ggplot(aes(x, y)) + geom_point(aes(color = ClusterID))
Another option is to name the legend in scale_color_discrete
:
ggplot(mydata, aes(x, y)) +
geom_point(aes(color = factor(ClusterID))) +
scale_color_discrete(name = "ClusterID")
Upvotes: 1