Change Continuous Color Range in ggplot2 Plot in R (Example) | Adjust Palette | colorRampPalette()

Опубликовано: 25 Июль 2026
на канале: Statistics Globe
1,396
44

How to adjust the continuous color range in a ggplot2 plot in the R programming language. More details: https://statisticsglobe.com/change-co...
R code of this video:

set.seed(568323) # Generate continuous example data
data <- data.frame(x = rnorm(500),
y = rnorm(500))

install.packages("ggplot2") # Install ggplot2 package
library("ggplot2") # Load ggplot2

ggp <- ggplot(data, aes(x, y, color = y)) + # ggplot2 scatterplot with default legend
geom_point()
ggp # Draw ggplot2 scatterplot

fun_color_range <- colorRampPalette(c("yellow", "red")) # Create color generating function

my_colors <- fun_color_range(20) # Generate color range
my_colors # Print color range

ggp + # Change colors in ggplot2 scatterplot
scale_colour_gradientn(colors = my_colors)

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com