Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R geom_平滑的ggplot2语法_R_Ggplot2 - Fatal编程技术网

R geom_平滑的ggplot2语法

R geom_平滑的ggplot2语法,r,ggplot2,R,Ggplot2,我使用以下函数将非线性曲线拟合到一组数据。我一直收到以下错误: Error in do.call("layer", list(mapping = mapping, data = data, stat = stat, : object 'y' not found 错误来自于geom_平滑fit。你能提出建议吗 以下是一些测试数据和功能: library("ggplot2") DF <- data.frame(RFP_fold=1:20, E=rnorm(20)) flim

我使用以下函数将非线性曲线拟合到一组数据。我一直收到以下错误:

Error in do.call("layer", list(mapping = mapping, data = data, stat = stat,  : 
 object 'y' not found 
错误来自于
geom_平滑
fit。你能提出建议吗

以下是一些测试数据和功能:

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 ~ a * (x / (x + K))',    # Forumla for fit
            start=list(a=max(y), K = 0.1),  # set the 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 
库(“ggplot2”)

DF我不知道为什么变量没有传递给geom_smooth,所以我只是在函数中添加了几个变量

flimPlot <- function(data) {

    y <- data$E
    x <- data$RFP_fold
    a <- max(dat$E)
    st <- list(a=a, K=0.1)
    fit <- nls(formula="E ~ a * (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 ~ a * (x / (x + K))",    # Forumla for fit
                 start=st,  # set the 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")
   }

flimPlot你真的是指
start=list(y=max(a),K=0.1)
,还是你本来打算
start=list(a=max(a),K=0.1)
?@BenBolker你是对的,我是说第二条路。在我提交问题之前,我一直在玩弄语法。@BenBolker,在我修正了拼写错误后,它仍然失败。此外,我还添加了一些可复制的数据。我不断得到y未找到的错误。