I make some plot with ggplot2 like this:
library(ggplot2)
ggplot(df, aes(x, y, col= col)) +
geom_point()
Everything is good but as soon I set another legend title as shown here, the continuous colour gradient changes to some points in the legend:
library(ggplot2)
ggplot(df, aes(x, y, col= col)) +
geom_point() +
guides(col= guide_legend(title= "Some title"))
How can I change just the title not the eastethic in the legend?
Data used here:
df <- data.frame(x= 1:10, y= 1:10, col= rnorm(10))
>Solution :
You need guide_colourbar instead of guide_legend
ggplot(df, aes(x, y, col = col)) +
geom_point() +
guides(col = guide_colourbar(title = "Some title"))

Though personally, I would normally just change the label of the color aesthetic:
ggplot(df, aes(x, y, col = col)) +
geom_point() +
labs(color = "Some title")
Which gives the same result with fewer keystrokes.

