I asked similar question and was told there's a duplicated question (R ggplot2 aes argument). I changed my code based on that answer but still does not work.
I'm writing a spider plot and can run it (without function). Then I want to write a function named "plottum" which can input some variables and make plots. But now it does not work.
Can anyone help me? Thanks! (I have changed my code a bit)
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" )