ggplot2,aes vs aes_string [英] ggplot2, aes vs aes_string

查看:157
本文介绍了ggplot2,aes vs aes_string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以由于失败 rcmdcheck()<,我需要用 aes_string 替换 aes / code>。

So I need to replace aes with aes_string due to failing rcmdcheck().

原始:

        aes(
          x = A,
          y = pmax(B, C, na.rm = TRUE),
          ),

我的困惑是关于 B C 。因为它们位于 pmax 函数中,所以我可以在它们周围加上引号吗?像这样:

My confusion is regarding B and C. Am I allowed to put quotes around them since they are inside the pmax function? Like so:

        aes_string(
          x = "A",
          y = pmax("B", "C", na.rm = TRUE),
          ),

以下还有另一个解决方案?:

Is the below yet another solution?:

        aes(
          x = .data$A,
          y = pmax(.data$B, .data$C, na.rm = TRUE),
          ),

已编辑:

R CMD检查错误是变量 A B <没有全局绑定/ code>和 C

The R CMD Check error is that there is no global binding for the variables A, B, and C.

推荐答案

区别在 aes aes_string 之间非常简单, aes_string 将解释描述参数的字符串。例如。以下作品

The difference between aes and aes_string is very simply, that aes_string will interpret the string that is describing the arguments. Eg. the following works

library(ggplot2)
data(mtcars)
ggplot(aes_string(x = "log(hp)", y = "1/log(mpg)", col = "factor(cyl)"), data = mtcars) + 
  geom_point() + 
  labs(col = 'cyl')

这也记录在 help(aes_string)页面


aes_和aes_string要求您显式引用输入中的或。

aes_ and aes_string require you to explicitly quote the inputs either with "" for aes_string(), or with quote or ~ for aes_().

但是正如MrFlick在评论中指出的那样,这些函数都是软弃用的,我相信这是为了保持兼容性而保留它们,但不鼓励使用。

But as MrFlick stated in the comments, these functions are all soft-deprecated, which I believe means that they are kept for compatibility but usage is discouraged.

这篇关于ggplot2,aes vs aes_string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆