我有一个在R中创建绘图的功能。我希望打印单元和功能名称。以下是代码。
library(ggplot2)
plotfunction <- function(feature, featur_name, feature_unit){
ggplot(aes(x = feature), data = mtcars) +
geom_histogram(binwidth = 0.5) +
labs(x = paste(featur_name, feature_unit), y = "Count, #")
}
plotfunction(mtcars$wt, "Displacement, ", expression({g}/{dm}^{3}))
该函数生成如下所示的图。
答案 0 :(得分:0)
不是最优雅的解决方案,但这里有:
{
"keys": ["super+s"],
"command": "toggle_white_space",
"args": {
"options": ["all", "none"]
}
},
(我离开了第一个参数,因为数据输入不是真正问题的一部分......虽然您可能不应该用plotfunction2 <- function(feature_name, feature_unit){
x.lab = paste0("expression(paste('", feature_name, "', ", feature_unit, "))")
ggplot(data = mtcars, aes(wt)) +
geom_histogram(binwidth = 0.5) +
labs(x = eval(parse(text = x.lab)))
}
plotfunction2("Displacement, ", "{g}/{dm}^{3}")
符号定义美学映射。)