R xlim geom_直方图错误:美学长度必须为1或与数据相同

R xlim geom_直方图错误:美学长度必须为1或与数据相同,r,ggplot2,R,Ggplot2,我正在尝试用自定义调色板绘制直方图。当我设置直方图的xlim时,问题就出现了 请参见以下可复制示例: # sample dataframe test_dt <- structure(list(col_1 = c(0.057, -0.063, -0.319, 0.02, 0.079, 0.007, -0.105, -0.084, 0.019, 0.28, -0.064, -0.243, -0.116, 0.079,

我正在尝试用自定义调色板绘制直方图。当我设置直方图的xlim时,问题就出现了

请参见以下可复制示例:

# sample dataframe
test_dt <- structure(list(col_1 = c(0.057, -0.063, -0.319, 0.02, 0.079, 
                                0.007, -0.105, -0.084, 0.019, 0.28, -0.064, -0.243, -0.116, 0.079, 
                                0.07, -0.187, -0.725, 0.134, 0.062, -0.056, -0.074, 0.392, -0.014, 
                                -0.062, 0.214, 0.371, 0.069, -0.03, 0.036, -0.175, 0.097, 0.358, 
                                0.153, -0.092, -0.038, -0.051, 0.017, -0.108, 0.133, 0.105, 0.187, 
                                -0.056, -0.316, 0.15, -0.142, 0.076, 0.242, -0.069, 0.155, 0.214, 
                                0.162, -0.037, -0.109, 0.111, -0.077, -0.435, 0.003, 0.187, 0.134, 
                                0.027, 0.107, 0.175, -0.355, -0.572, 0.038, -0.209, -0.263, -0.147, 
                                -0.23, -0.174, 0.203, -0.118, 0.008, -0.268, -0.001, 0.227, -0.019, 
                                0.08, 0.044, -0.065, -0.131, 0.093, 0.127, -0.131, 0.039, 0.045, 
                                0.032, 0.343, 0.053, -0.033, 0.453, 0.07, -0.225, 0.094, 0.002, 
                                -0.119, 0.014, -0.125, 0.003, -0.48)), row.names = c(NA, -100L
                                ), class = "data.frame")
# colour palette
RBW <- colorRampPalette(c("darkred","white","darkblue"))

# plot histogram without xlim
ggplot(test_dt) +
    geom_histogram(aes(x=col_1),
                   position = "identity",
                   bins     = 60,
                   color    = "grey10",
                   fill     = RBW(60))

代替
xlim
,添加
+coord\u笛卡尔(xlim=c(-2,2))

库(ggplot2)
```r
ggplot(测试图)+
几何直方图(aes(x=col_1),
position=“identity”,
垃圾箱=60,
color=“grey10”,
填充=RBW(60))+
坐标笛卡尔(xlim=c(-2,2))

由(v0.3.0)于2020年2月11日创建

# plot histogram with xlim
ggplot(test_dt) +
    geom_histogram(aes(x=col_1),
                   position = "identity",
                   bins     = 60,
                   color    = "grey10",
                   fill     = RBW(60)) +
    xlim(-2,2)