r - ggplot2 syntax for geom_smooth -
i have following function using fit non linear curve set of data. keep receiving following error:
error in do.call("layer", list(mapping = mapping, data = data, stat = stat, : object 'y' not found
the error coming geom_smooth
fit. can offer suggestions?
below test data , function:
library("ggplot2") df <- data.frame(rfp_fold=1:20, e=rnorm(20)) flimplot <- function(data) { ggplot(data, aes(x=rfp_fold, y=e)) + geom_point(shape=1) + geom_smooth(method=nls, # add non linear regression fit formula='y ~ * (x / (x + k))', # forumla fit start=list(a=max(y), k = 0.1), # set parameters se = false, # no shaded ci fullrange=true) # extend regression line } flimplot(df) # error in do.call("layer", list(mapping = mapping, data = data, stat = stat, : object 'y' not found
i don't know why variables not being passed geom_smooth added few more variables in function.
flimplot <- function(data) { y <- data$e x <- data$rfp_fold <- max(dat$e) st <- list(a=a, k=0.1) fit <- nls(formula="e ~ * (rfp_fold / (rfp_fold + k))", dat, start=st ) k <- round(coef(fit)) ggplot(data, aes(x=rfp_fold, y=e)) + geom_point(shape=1) + #geom_text(aes(3,15, label = paste(expr, k, sep=""))) + #annotate("text", x = 3, y = 15, label = paste(expr, k, sep="") ) + stat_smooth( geom = "smooth", method=nls, # add non linear regression fit formula="y ~ * (x / (x + k))", # forumla fit start=st, # set parameters #se = false, # no shaded ci fullrange=true) + # extend regression line scale_y_continuous(limits = c(0, 20)) + theme(plot.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.border = element_blank(), panel.background = element_blank(), axis.line = element_line(color = 'black'), text = element_text(size=12), #axis.title.x = element_blank(), #axis.title.y = element_blank(), legend.justification=c(1,0)) + ylab("fret e%") + xlab("acceptor intensity") }
Comments
Post a Comment