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 从平滑曲线中提取特定数量的数据点_R_Ggplot2_Shiny_Plotly - Fatal编程技术网

R 从平滑曲线中提取特定数量的数据点

R 从平滑曲线中提取特定数量的数据点,r,ggplot2,shiny,plotly,R,Ggplot2,Shiny,Plotly,我有一个数据集df,我用它来绘制散点图。以下是它的代码: g <- ggplot() + theme_bw() + geom_point(data = df, aes_string(df[,1], df[,2]), color = 'red')+ geom_smooth(data = df, aes_string(df[,1], df[,2]),formula = y ~ splines::bs(x, df = input$

我有一个数据集
df
,我用它来绘制散点图。以下是它的代码:

 g <- ggplot() + theme_bw() +
                geom_point(data = df, aes_string(df[,1], df[,2]), color = 'red')+
                geom_smooth(data = df, aes_string(df[,1], df[,2]),formula = y ~ splines::bs(x, df = input$degree_1), method = "lm", color = "green3", level = 1, size = 0.5)
现在,我想用两条垂直线切割平滑曲线,并提取位于这两条线之间的曲线的数据点:

v_f1 <- subset(r, x > input$Vert1 & x < input$Vert2, select = c(x,y))
v_f1 input$Vert1&x
input$Vert1
input$Vert2
是用于更改垂直线位置的滑块

我想要的是: 我希望能够通过这些垂直线控制在上述命令中被子集和提取的点的数量


现在,它正在提取一个随机数目的点,我希望用户能够控制它。例如,如果我想切割轮廓,在一种情况下提取100点,在另一种情况下提取120点,依此类推。或者我可以为所有案例设置一个固定数字。

ggplot
之外安装模型,并使用
predict
。您能详细说明一下吗?@kolas0202请澄清您希望如何取样您的观点。它们是沿x轴(相同的dx)均匀分布还是沿曲线(相同的ds)均匀分布?
x@billy34我想对我的点进行采样,使它们沿曲线均匀分布,即相同的ds。在
ggplot
外部拟合模型,并使用
predict
。你能详细说明一下吗?@kolas0202请说明你想如何对点进行采样。它们是沿x轴(相同的dx)还是沿曲线(相同的ds)均匀分布?
x@billy34我想对我的点进行采样,以便它们沿曲线(即相同的ds)均匀分布。
v_f1 <- subset(r, x > input$Vert1 & x < input$Vert2, select = c(x,y))