简体   繁体   English

将 RColorBrewer 与 scale_fill_gradientn() 一起使用,我不断收到相同的错误

[英]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.

相关问题 如何获得多个具有相同比例的 ggplot2 scale_fill_gradientn? - How to get multiple ggplot2 scale_fill_gradientn with same scale? R:使用带有geom_tile()和scale_fill_gradientn()的颜色划分热图 - R: Dividing heat map using colors with geom_tile() and scale_fill_gradientn() 使用 scale_fill_gradientn 将特定颜色分配给条形 plot 中的确定值 - Assign specific color to definite value in bar plot using scale_fill_gradientn 在 scale_fill_gradientn 中使用绝对值而不是相对值 - Use absolute values not relative values in scale_fill_gradientn 为负值和正值定义颜色渐变 scale_fill_gradientn() - define color gradient for negative and positive values scale_fill_gradientn() 用ggplot2的scale_fill_gradientn表示,恒定渐变 - Representation with, scale_fill_gradientn ggplot2, constant gradient 使用 scale_fill_gradientn() 将颜色比例转换为概率转换颜色分布 - Transform color scale to probability-transformed color distribution with scale_fill_gradientn() scale_fill_gradientn() 成功填充 map 但未能在图例中显示所有 colors - The scale_fill_gradientn() successfully fills map but fails showing all colors in the legend 在ggplot中与geom_bin2d结合获得相对计数,并正确使用scale_fill_gradientn - Get relative count in ggplot combined with geom_bin2d, and proper use of scale_fill_gradientn 在热图中为比例设置 scale_fill_gradientn 的限制(从 0 到 1 的值带有蓝色刻度,0 是白色,大于 1 的值带有红色刻度) - Set limits for scale_fill_gradientn for ratios (values from 0 to 1 with blue scale, 0 is white and values over 1 with red scale) in heatmap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM