【发布时间】:2014-08-07 13:47:13
【问题描述】:
我在ggplot2 中创建了一个使用scale_fill_gradientn 的情节。我想在比例图例的最小值和最大值处添加文本。例如,在图例最小值处显示“Minimum”,在图例最大值处显示“Maximum”。有些帖子使用离散填充并添加带有数字而不是文本的标签(例如here),但我不确定如何使用labels 功能和scale_fill_gradientn 仅在最小值和最大值处插入文本。目前我很容易出错:
Error in scale_labels.continuous(scale, breaks) :
Breaks and labels are different lengths
这种类型的比例/填充是否可以在 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")
【问题讨论】:
标签: r ggplot2 label legend fill