r - R 中的平滑曲线图

标签 r graph plot

我有一个折线图,当前显示图表上每个点之间的直线。

Graph with straight lines

有没有一种方法可以使线条成为平滑的曲线,而不是简单地“连接点”?

这是我用来生成上述图表的代码摘录:

  plot(dataPlotsX,dataPlotsY, type="o", col="red", ann=FALSE)

  title(main=plotTitle, col.main="red", font.main=4)
  title(xlab="Time (hours)", col.lab="red")
  title(ylab="Discharge (m^3/s per 10mm)", col.lab="red")

供引用;

dataPlotsX = c(0, 1, 2, 3, 4, 5, 6) 
dataPlotsY = c(0.000000, 5.772690, 17.303517, 12.981276,  2.886345,  0.000000,  0.000000)

非常感谢

柯本

最佳答案

您可以使用样条线进行插值,例如:

# run this code just after your example
# to add a spline interpolating the points
s <- smooth.spline(dataPlotsX,dataPlotsY)
smooth <- predict(s,seq.int(from=min(dataPlotsX),to=max(dataPlotsX),length.out=10000))
lines(smooth,type="l",col='blue')

enter image description here

关于r - R 中的平滑曲线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33508190/

相关文章:

c++ - boost 图形库 : Merging undirected graphs

减少R中图的pdf文件大小

R:如何使用字符串调用函数并将参数粘贴到该函数中?

python - 在 python 中嵌入 R 代码

r - as_datetime() 错误 : All formats failed to parse

r - 将列拆分为多列

c# - 如何绘制平滑/圆角/曲线图? (C#)

algorithm - 最小化有向图中树路径的成本

python - matplotlib 中的 "Repel"注释?

Python:如果我有 x、y 和 z 作为某些参数的函数,如何绘制通用 3D 对象?