使用时缩放填充连续发散 from colorspace
里面一个for loop
or function
不粘贴name
图例标题并通过错误,如下例所示。
library("ggplot2")
library(colorspace)
set.seed(100)
df <- data.frame(country = LETTERS, V = runif(26, -40, 40))
df$country = factor(LETTERS, LETTERS[order(df$V)]) # reorder factors
fun_plt<-function(x){
x<-df
gg <- ggplot(df, aes(x = country, y = V, fill = V)) +
geom_bar(stat = "identity") +
labs(y = "Under/over valuation in %", x = "Country") +
coord_flip() + theme_minimal()
gg
#Lets say want to paste test in the leged when running through function
tt<-"test"
gg2<-gg+
scale_fill_continuous_diverging(name=paste0(tt,"V"),
palette = "Blue-Red 3", l1 = 30, l2 = 100, p1 = .9, p2 = 1.2)
gg2
}
fun_plt(df)
它独立工作得很好,但在函数内运行时会出错。
这是底层如何处理的问题ggplot2
尺度函数(discrete_scale
, continuous_scale
, binned_scale
)由比例函数调用colorspace
。调用环境并不总是被保留,因此对某些参数的非标准评估,例如name
没有按预期工作。
我现在已经在版本 2.0-1(当前的开发版本)中修复了该问题colorspace
在 R-Forge 上。安装这个应该可以修复这个错误:
install.packages("colorspace", repos = "http://R-Forge.R-project.org")
更新:同时这也已经通过CRAN发布了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)