【发布时间】:2019-07-26 09:27:56
【问题描述】:
我有一个带有 400 多个数据点的 df,我想用 palette = "Blues" 为 RColorBrewer 包着色。
我绘制了我的数据,甚至将palette 的颜色输入最大值扩展到了我的数据点的长度,以避免收到“错误消息”(见下文),但图中的颜色没有改变(仅一条黑线)。
错误:美学必须是长度 1 或 与数据相同(427):填充
我创建了一个dummy df 以使我的问题可重现:
library(ggplot2)
library(RColorBrewer)
color = colorRampPalette(rev(brewer.pal(n = 9, name = "Blues")))(300)
df = (curve(3*x^2 + x, from=1, to=10, n=300, xlab="xvalue", ylab="yvalue",
col="blue", lwd=2, main="Plot of (3x^2 + x)"))
dfx = matrix(data = df$x, ncol = 1)
dfy = matrix(data = df$y, ncol = 1)
dfa = cbind(dfx,dfy)
DF = ggplot(dfa, aes(x = dfx, y = dfy)) +
geom_point(fill = color)
我希望曲线在开始时 (1,4) 变为浅蓝色,直到结束时黑暗度增加(结束时为深蓝色 (10,310))。
提前致谢!
【问题讨论】: