Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 按中值排序的动态ggplot函数_R_Ggplot2 - Fatal编程技术网

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')

test
aes\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')