ggplot2 color gradient

  1. Use the ggplot() function to initialize the plot and specify the data and aesthetics (aes).
  2. Add the geom_point() function to create a scatter plot with points representing the data.
  3. Inside the aes() function, specify the variable you want to use for the color aesthetic.
  4. Add the scale_color_gradient() function to specify the type of color gradient you want to use, such as "viridis" or "blues".
  5. Within the scale_color_gradient() function, set the low and high values for the color gradient using the low and high arguments.
  6. Optionally, you can further customize the color gradient by adjusting parameters such as midpoint, limits, and breaks within the scale_color_gradient() function.