我正在编写一个蜘蛛图并且可以运行它(没有功能)。然后,我想编写一个可以输入一些变量并进行绘图的函数。这是我的情节。但是它不起作用,错误是“无法将连续变量映射到形状”,但是在我的数据中,“ cstatus”绝对是因素。谁能帮我?谢谢!
plottum = function(data,time,pct,name,censor,treat){
time=noquote(time)
pct=noquote(pct)
name=noquote(name)
censor=noquote(censor)
treat=noquote(treat)
ggplot(data,aes(x=time,y=pct,group=name)+
geom_line(aes(color=treat)+
geom_point(aes(shape=censor,color=treat)
}
plottum(tumorgrowth,"time","percentChange","name","cstatus","treatment")
这是我的数据。 图书馆(tumgr) 库(ggplot2)
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 days
cstatus = factor(ifelse(date > 250, 0, 1))
})))
现在我更改为
plottum = function(data,time,pct,name,censor,treat){
time=enquo(time)
pct=enquo(pct)
name=enquo(name)
censor=enquo(censor)
treat=enquo(treat)
ggplot(data,aes_string(quo_name(x=time,y=pct,group=name)))+
geom_line(aes(color=treat)+
geom_point(aes(shape=censor,color=treat)
}
plottum(tumorgrowth,time,percentChange,name,cstatus,treatment )
,但仍然无法正常工作。