[英]Using the RColorBrewer with scale_fill_gradientn(), I keep getting the same error
I'm working with the following code:我正在使用以下代码:
library('colorspace')
blups <- brewer.pal(9, 'BuPu')
geom_tile(aes(lon, lat, fill = predicted_price), alpha = 0.8) + scale_fill_gradientn(colors = blups)
The error msg is:错误消息是:
Check your call of scale_fill_gradientn().检查您对 scale_fill_gradientn() 的调用。 Did you correctly specify the argument colors?您是否正确指定了参数 colors?
I've tried various combinations of code, and the error msg is always the same.我试过各种代码组合,错误消息总是一样的。
What's going on?这是怎么回事?
Try this: You need library(RColorBrewer)
试试这个:你需要library(RColorBrewer)
library(RColorBrewer)
blups <- brewer.pal(9, 'BuPu')
# Example data:
library(reshape)
# Data
set.seed(8)
m <- matrix(round(rnorm(200), 2), 10, 10)
colnames(m) <- paste("Col", 1:10)
rownames(m) <- paste("Row", 1:10)
# Transform the matrix in long format
df <- melt(m)
colnames(df) <- c("x", "y", "value")
library(ggplot2)
ggplot(df, aes(x = x, y = y, fill = value)) +
geom_tile()+
scale_fill_gradientn(colors = blups)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.