scale_fill_gradient2 函数是 ggplot2 中用于设置填充颜色渐变的函数之一,它允许你定义两种颜色之间的渐变,并且可以设置一个中间值(中点)来表示数据的某个特定值。 基础概念 scale_fill_gradient2 函数允许你创建一个双色渐变,其中包含一个低值颜色、一个高值颜色和一个中间值颜色。这个中间值颜色通常用来表示数据...
将scale_fill_gradientn()函数应用于ggplot2图形中的相应图层,以实现反转一半的色阶效果。 以下是一个示例代码: 代码语言:R 复制 library(ggplot2) # 创建一个示例数据集 data <- data.frame(x = 1:10, y = 1:10, z = 1:10) # 创建一个散点图 plot <- ggplot(data, aes(x, y, fill = z))...
更复杂的scale_fill_gradientn()函数可以使用colours参数设置多个中间颜色,适合需要精细控制渐变色的场景:...
+scale_x_continuous(expand =c(0,0))+ +scale_y_continuous(expand =c(0,0)) > erupt +scale_fill_gradient(limits =c(0,0.04)) 下图左 > erupt +scale_fill_gradient(limits =c(0,0.04),low="white",high="black") 下图中 > erupt +scale_fill_gradient2(limits =c(-0.04,0.04),midpoint=m...
scale_fill_gradient(low = "lightblue", high = "red", limits = c(0, 8000)) # We'll use the ChickWeight data set and create a base plot called `cw_sp` (for ChickWeight scatter plot) cw_sp <- ggplot(ChickWeight, aes(x = Time, y = weight)) ...
您可以使用scale_fill_gradient: df4 <- data.frame(rnorm(10000,100,10)) colnames(df4) <- c("Value") library(ggplot2) ggplot(df4, aes(x=Value)) + geom_histogram(binwidth = 1, alpha=0.8, aes(fill=..count..)) + scale_fill_gradient(low = "red", high = "green") + labs(title...
ggplot(heightweight,aes(x=ageYear,y=heightIn,fill=weightLb))+ geom_point(size=2.5,shape=21)+ scale_fill_gradient(low = 'white',high = 'purple') #把一个连续型变量映射给某个属性后,并不妨碍同时将分类变量映射给其他属性 ggplot(heightweight,aes(x=ageYear, ...
value = mean(value)), fill = 'white', aes(label = value), fontface = 4, size = 6) + scale_fill_gradientn(colours = c("#e86a68", "#e86a68", "#f0ea94", "#629353","#629353"), values = c(0, 0.1, 0.55, 0.95, 1), guide = 'none') + ...
b + scale_fill_grey()b + scale_fill_grey(start=1, end=)连续型变量 gradient 创建渐变色 distiller使用ColorBrewer的颜色 identity 使用color变量对应的颜色,对离散型和连续型都有效 scale_color_gradient 双色渐变(低-高)scale_color_gradient2发散颜色渐变(低-中-高)scale_color_gradientn创建n色渐变...
scale_colour_gradient()和scale_fill_gradient():指定双色梯度。顺序由低到高。 双色梯度low和high控制梯度两颜色。 例: 1 2 3 ggplot() +geom_point(data = mtcars, aes(x = mpg, y = disp, color = qsec)) + scale_colour_gradient(low ="green", high ="red") ...