R 按中值排序的动态ggplot函数
这很好:R 按中值排序的动态ggplot函数,r,ggplot2,R,Ggplot2,这很好: test <- function(x, y) { ggplot(iris, aes_string(x = x, y = y)) + geom_boxplot() + xlab(x) + coord_flip() } test('Species', 'Sepal.Width') testaes\u string只需要字符串,而不需要像reorder这样的函数。使用最新的ggplot2,您可以使用ensym将字符串转换为可与aes()而不是aes\
test <- function(x, y) {
ggplot(iris, aes_string(x = x, y = y)) +
geom_boxplot() +
xlab(x) +
coord_flip()
}
test('Species', 'Sepal.Width')
testaes\u string
只需要字符串,而不需要像reorder
这样的函数。使用最新的ggplot2
,您可以使用ensym
将字符串转换为可与aes()
而不是aes\u字符串一起使用的SUMBOL
test <- function(x, y) {
ggplot(iris, aes(x = reorder(!!ensym(x), !!ensym(y), FUN = median), y = !!ensym(y))) +
geom_boxplot() +
xlab(x) +
coord_flip()
}
test('Species', 'Sepal.Width')
测试
test <- function(x, y) {
ggplot(iris, aes(x = reorder(!!ensym(x), !!ensym(y), FUN = median), y = !!ensym(y))) +
geom_boxplot() +
xlab(x) +
coord_flip()
}
test('Species', 'Sepal.Width')