Reputation: 75
I have runned the following code:
ggplot(Cars)) +
geom_point(aes(colour = Model)) +
labs(title = "Cars in the US") +
labs(colour = "USD")
And the small box to the right of the plot turns in a blue tone (down below). However I want to have it in two version, on in green tone and the other in red tone (red, orange, yellow depending on value). How do I do that?
Upvotes: 0
Views: 118
Reputation: 1449
If you want two different graphs with colors of your choice for each one, you could do this with the function scale_color_gradient
### Miscellaneous
library(ggplot2)
library(ggpubr)
data(cars)
### Initiating plots
firstPlot <- ggplot(cars, aes(x=speed, y=dist)) +
geom_point(aes(colour = speed)) +
labs(title = "Cars in the US") +
labs(colour = "USD") +
scale_color_gradient2(midpoint=15,
low="yellow",
mid="orange",
high="red", space="Lab")
secondPlot <- ggplot(cars, aes(x=speed, y=dist)) +
geom_point(aes(colour = speed)) +
labs(title = "Cars in the US") +
labs(colour = "USD") +
scale_color_gradient2(midpoint=15,
low="#56ffba",
mid="#2bc888",
high="#078954", space="Lab")
### Display plots
ggarrange(firstPlot, secondPlot, nrow=1, ncol=2)
Upvotes: 1