I asked similar question,并被告知存在重复的问题(R ggplot2 aes argument)。我根据该答案更改了代码,但仍然无法正常工作。
我正在编写一个蜘蛛图并且可以运行它(没有功能)。然后,我想编写一个名为“ plottum”的函数,该函数可以输入一些变量并进行绘制。但是现在不起作用了。
有人可以帮助我吗?谢谢! (我对代码做了一些更改)
library(ggplot2)
library(tumgr)
set.seed(1234)
tumorgrowth = sampleData
tumorgrowth = do.call(rbind,
by(tumorgrowth, tumorgrowth$name,function(subset) within(subset,
{ treatment = ifelse(rbinom(1,1,0.5), "Drug","Control")
#random classfied
o = order(date)
date = date[o]
size = size[o]
baseline = size[1]
percentChange = 100*(size-baseline)/baseline
time = ifelse(date > 250, 250, date) ## data censored at 250
cstatus = factor(ifelse(date > 250, 0, 1))
})))
# Above codes work well, and problem is this plottum function
plottum = function(data,time,pct,name,censor,treat){
ggplot(data,aes(x=data[,time],y=data[,pct],group=data[,name]))+
geom_line(aes(color=data[,treat]))+
geom_point(aes(shape=data[,censor],color=data[,treat]))
}
plottum(tumorgrowth,"time","percentChange","name","cstatus","treatment" )
答案 0 :(得分:1)
select stat.*,
(
Select
1
From
table1 a, table2 pg
Where
a.field_1::Text = stat.field_1::Text And
a.field_2::Text = stat.field_2::Text And
stat.field_3::Text = pg.field_3::Text And
a.field_4= pg.field_4
limit 1
)
from table3 stat
where field_1= 'xyz';
选项2: aes_string (已过时,此名称已过时,不再使用,这意味着使用新方法开始移动的时间)
scatter_by <- function(data, x, y) {
x <- enquo(x)
y <- enquo(y)
ggplot(data, aes(!!x, !!y)) + geom_point()
}
scatter_by(mtcars, disp, drat)