我在创建打印ggplot2使用scale_fill_gradientn.我想在缩放图例的最小值和最大值处添加文本.例如,在图例最小显示"最小"和图例最大显示"最大".有些帖子使用离散填充并添加带有数字而不是文本的标签(例如此处),但我不确定如何使用该labels功能scale_fill_gradientn仅在最小和最大时插入文本.目前我很容易出错:
Error in scale_labels.continuous(scale, breaks) :
Breaks and labels are different lengths
Run Code Online (Sandbox Code Playgroud)
这种类型的缩放/填充是否可以在ggplot2中使用此文本标签?
# The example code here produces an plot for illustrative purposes only.
# create data frame, from ggplot2 documentation
df <- expand.grid(x = 0:5, y = 0:5)
df$z <- runif(nrow(df))
#plot
ggplot(df, aes(x, y, fill = z)) + geom_raster() +
scale_fill_gradientn(colours=topo.colors(7),na.value = "transparent")
Run Code Online (Sandbox Code Playgroud)