Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.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 GGP图上的抛物线参考线_R_Ggplot2 - Fatal编程技术网

R GGP图上的抛物线参考线

R GGP图上的抛物线参考线,r,ggplot2,R,Ggplot2,我正在将我的绘图移到ggplot中。除了这一个(从中获得的代码),几乎都在那里: 说清楚。我正在参考线上绘制数据(上图)。下图显示了我的数据和我在获取参考线方面的拙劣尝试(这显然不起作用)。您所做的是将抛物线拟合到数据中,而不是绘制先前定义的抛物线。调整您必须的ggplot并不难 与之前相同的开始(尽管实际上没有在任何地方使用betseq) 若要保存重复,请定义垂直线(边)的位置,该位置还可用于定义抛物线的左右端点(范围) 我明白我的做法是错误的。必须从某个地方开始。你的看起来不错。谢谢我会

我正在将我的绘图移到ggplot中。除了这一个(从中获得的代码),几乎都在那里:


说清楚。我正在参考线上绘制数据(上图)。下图显示了我的数据和我在获取参考线方面的拙劣尝试(这显然不起作用)。

您所做的是将抛物线拟合到数据中,而不是绘制先前定义的抛物线。调整您必须的
ggplot
并不难

与之前相同的开始(尽管实际上没有在任何地方使用
betseq

若要保存重复,请定义垂直线(
)的位置,该位置还可用于定义抛物线的左右端点(
范围


我明白我的做法是错误的。必须从某个地方开始。你的看起来不错。谢谢我会试一试的!好的,看起来不错。但是我如何在上面绘制我的数据呢?我不知道数据的格式,但是根据您显示的内容猜测,添加
geom_线(data=a,aes(x=num,y=s,color=ss))
#Set the bet sequence and the % lines
betseq <- 0:700 #0 to 700 bets
perlin <- 0.05 #Show the +/- 5% lines on the graph

#Define a function that plots the upper and lower % limit lines
dralim <- function(stax, endx, perlin) {
  lines(stax:endx, qnorm(1-perlin)*sqrt((stax:endx)-stax))
  lines(stax:endx, qnorm(perlin)*sqrt((stax:endx)-stax))
}

#Build the plot area and draw the vertical dashed lines
plot(betseq, rep(0, length(betseq)), type="l", ylim=c(-50, 50), main="", xlab="Trial Number", ylab="Cumulative Hits")
abline(h=0)
abline(v=35, lty="dashed") #Seg 1
abline(v=185, lty="dashed") #Seg 2
abline(v=385, lty="dashed") #Seg 3
abline(v=485, lty="dashed") #Seg 4
abline(v=585, lty="dashed") #Seg 5

#Draw the % limit lines that correspond to the vertical dashed lines by calling the
#new function dralim.
dralim(0, 35, perlin) #Seg 1
dralim(36, 185, perlin) #Seg 2
dralim(186, 385, perlin) #Seg 3
dralim(386, 485, perlin) #Seg 4
dralim(486, 585, perlin) #Seg 5
dralim(586, 701, perlin) #Seg 6
ggplot(a, aes(x=num,y=s, colour=ss)) +geom_line() +stat_smooth(method="lm", formula="y~poly(x,2)") 
#Set the bet sequence and the % lines
betseq <- 0:700 #0 to 700 bets
perlin <- 0.05 #Show the +/- 5% lines on the graph
#Define a function that plots the upper and lower % limit lines
dralim <- function(stax, endx, perlin) {
  c(geom_line(data = data.frame(x=stax:endx, 
                                y=qnorm(1-perlin)*sqrt((stax:endx)-stax))),
    geom_line(data = data.frame(x=stax:endx, 
                                y=qnorm(perlin)*sqrt((stax:endx)-stax))))
}
edges <- data.frame(x=c(0, 35, 185, 285, 485, 585, 700))
ranges <- data.frame(left = edges$x[-nrow(edges)],
                     right = edges$x[-1] + 1)
ggplot(mapping=aes(x=x,  y=y)) +
  geom_vline(data=edges, aes(xintercept = x), linetype="dashed") +
  lapply(seq_len(nrow(ranges)), 
         function(r) {dralim(ranges$left[r], ranges$right[r], perlin)}) +
  scale_y_continuous("Cumulative Hits", lim=c(-50,50)) +
  scale_x_continuous("Trial Number")