Skip to content

Instantly share code, notes, and snippets.

@cimentadaj
Created August 16, 2016 22:56
Show Gist options
  • Save cimentadaj/4d45ec1934db2d4a7ffdd449911eb468 to your computer and use it in GitHub Desktop.
Save cimentadaj/4d45ec1934db2d4a7ffdd449911eb468 to your computer and use it in GitHub Desktop.
# Let's create a scatterplot with a discrete variable in the X axis
p <- ggplot(housing[!is.na(housing$region),], aes(x=State, y=Land.Value, color=Home.Value)) + geom_point(alpha=0.3); p
# Note that we set the color to be conditional on a continuous variables(Home.Value)
# Here we set the color to be blue when the Home.Value variable is low and red when it's high
p + scale_color_gradient(low="blue", high="red", name= "Home Value")
# You can do similarly with the scale_color_gradient2, but it has a different default color schem
p + scale_color_gradient2(low=muted("red"), mid="white", high=muted("black"), name= "Home Value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment