R中类似的seaborn情节

don*_*ati 2 plot r ggplot2

我想用R测试seaborn中的所有情节我想在R中绘制类似的seaborn情节,但是我无法在R seaborn图中完成相似的 图形

我更新的R代码是

x = seq(from = 0,to = 14,length.out = 100)
for(i in seq(1,6)){
    print(sin(x + i * .5)*(7 - i))
    plot(x,sin(x + i * .5)*(7 - i))
}
Run Code Online (Sandbox Code Playgroud)

eip*_*i10 5

您的代码每次循环都会创建一个新的图.用于lines向现有绘图添加线条.

plot(x, sin(x + 1 * .5)*(7 - 1), type="l")
for(i in seq(2,6)) {
  lines(x, sin(x + i * .5)*(7 - i), col=i)
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

您也可以这样做ggplot2:

library(tidyverse)  # loads several related packages including ggplot2 and purrr, both of which we use below.

my_fun = function(x, i) {
  sin(x + i  * .5)*(7 - i)
}

ggplot(data.frame(x=x), aes(x)) + 
  map2(1:6, hcl(seq(15,375,length=7)[1:6],100,65), function(ii,cc) {
  stat_function(fun=my_fun, args=list(i=ii), col=cc)
  }) +
  theme_classic()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述