修改ggplot函数外的aes列表 [英] Modify aes list outside ggplot function
问题描述
这是我在论坛上关于R的第一个问题,如果我在提出问题或指定标题时犯了错误,我很抱歉。
This is my first question about R in a forum, so sorry in advance if I made any mistake formulating the question or specifying the title.
关键在于,对于具有ggplot的特定任务,我定义ggplot函数之外的美学,然后将其作为参数提供。
The point is that for a particular task with ggplot I define the aesthetics outside the ggplot function and then provide it as an argument.
>mytmpaes<-aes(x=Sample,y=ddCt.lin,ymax=ddCt.lin+ddCt.lin.sd,ymin=ddCt.linddCt.lin.sd,fill=factor(endog))
>my.ggplot(x,mytmpaes)
但有时我只想修改mytmpaes列表的某些对象,而不用使用aes()定义所有这些对象。但是,我真的不知道如何处理这个特殊的列表。 aes列表如下所示:
But sometimes I just want to modify some objects of the mytmpaes list without defining all of them againg using aes(). However, I don't really know how to deal with this special list. The aes list looks like this:
>mytmpaes
List of 5
$ x : symbol Sample
$ y : symbol ddCt.lin
$ ymax : language ddCt.lin + ddCt.lin.sd
$ ymin : language ddCt.lin - ddCt.lin.sd
$ fill : language factor(Rep)
我想出了如何修改其中的一些内容: p>
I figured out how to modify some of them like this:
> mytmpaes$x<-as.symbol('Names')
> mytmpaes$fill<-call('factor',quote(target))
> mytmpaes
List of 5
$ x : symbol Names
$ y : symbol ddCt.lin
$ ymax: language ddCt.lin + ddCt.lin.sd
$ ymin: language ddCt.lin - ddCt.lin.sd
$ fill: language factor(endog)
然而,我找不到用相似的表达式修改ymax或ymin的方法。
例如,我想将ymax更改为'ddCt.log2 - ddCt.log2.sd'。
However, I couldn't find the way to modify the ymax or ymin with a similar expression. For example, I would like to change ymax to 'ddCt.log2 - ddCt.log2.sd'.
有人可以给我一些建议吗?还有,是否有更正确的方法来修改aes列表?
Can someone give me some advise for it? Also, is there a more correct way to modify the aes list?
谢谢,
Alejandro
Alejandro
推荐答案
我认为您正在寻找 substitute
:
返回(未评估的)表达式expr的分析树,代替env中的任何变量
returns the parse tree for the (unevaluated) expression expr, substituting any variables bound in env
举个例子:
And by way of an example:
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
y = rnorm(30))
## Make an aes
tmpaes <- aes(x = gp, y = y , ymin = -2 , ymax = 2 )
## Plot with it
ggplot(df) +
geom_point( tmpaes )
## Modify aes with a new variable
new <- 10
tmpaes$ymax <- substitute( new )
## replot
ggplot(df) +
geom_point( tmpaes )
这篇关于修改ggplot函数外的aes列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!