我有一个函数,其唯一目的是生成条形图。我的数据集称为south
。
# ......................................................................................
# Data for my example
south = matrix(data = sample(x = c("A","B","C"), size = 1032, replace = T), ncol = 12)
# ......................................................................................
# Function to graph the count of 'A', 'B', and 'C' from 'data'
graphMaker = function(system){
system %>%
as.data.frame() %>%
gather(key = "Key", value = "Values") %>%
ggplot(aes(Values, fill = Values)) +
geom_bar() +
labs(title = ________________)
}
# ......................................................................................
如何获取图形标题为提供给函数的字符串 参数
system
?
如果我尝试labs(title = system)
,则会得到一个标题为“ C”的图表。
最终,这就是我希望图形显示的样子。
答案 0 :(得分:4)
只需使用substitute
labs(title = substitute(system))