r - 自定义填充渐变在 self$oob(x, range = limits) 中产生错误:尝试应用非函数
问题描述
我正在尝试使用ggplot
自定义填充渐变创建一个绘图。我想设置填充渐变的限制,并在 oob 上使用 squish 参数来设置填充渐变的限制,但我最终得到了错误:Error in self$oob(x, range = limits) : attempt to apply non-function.
该错误应该能够使用下面的代码重现:
# Libraries
library(ggplot2)
library(scales)
# Create data frame
df <- data.frame("name" = c("A", "B", "C", "D", "E", "F", "G", "H"),
"percent" = c(0, 5, 10, 11, 22, 25, 30, 80),
"differential" = c(-20, -10, -5, 5, 10, 22, 30, 50))
# Plot
p <- ggplot(df, aes(percent, differential, fill = differential))+
geom_point(shape = 21, colour = "black")+
scale_fill_gradient2(low = "#C93135",
high = "#1375B7",
mid = "grey90",
midpoint = 0,
aesthetics = "fill",
limits = c(-30,30),
oob = squish(x=df$differential,
range=c(-30,30)))
p
任何帮助将不胜感激!先感谢您。
解决方案
正如 P.Chakytei 所指出的,我只需要在oob = squish
没有所有额外参数的情况下使用。
推荐阅读
- c# - C# 在控制台应用程序中捕获屏幕
- python - 条件平均划分为
- javascript - 如何在javascript中添加购物车中的数字并使用小数点后的数字正确显示它们
- javascript - 将多边形转换为倒多边形,即从视口矩形中切出负多边形
- html - 使用 grequests 从异步请求中提取文本
- android - 使用 osmdroid 在当前位置居中地图
- java - 静态方法无法访问调用者类名
- python-3.x - 为什么我在代码中所做的更改没有写入我创建的新文件?
- css - 在 R 的闪亮应用程序中更改整个字体的最简单方法?
- python - 手动终止 Scipy Minimize()