Zhenguo Zhang resets the scale:
In one ggplot figure, normally you can only use one scale for each aesthetic mapping. For example, if you use
scale_color_manual()
to set the color scale for a layer, you cannot use anotherscale_color_manual()
for another layer, or set the color scale more then once in the functionaes()
. However, you can use thenew_scale_color()
function from theggnewscale
package to add a new scale for the same aesthetic mapping in different layers.In this post, I will showcase how to use the
new_scale_color()
function to add two different color scales in a ggplot figure. The first scale will be for a discrete variable (e.g., number of cylinders), and the second scale will be for a continuous variable (e.g., density level).
Click through for the code and a demonstration.
Leave a Comment