繁体   English   中英

R中类似的海洋积

[英]Similar seaborn plot in R

我想用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))
}

您的代码每次循环都会创建一个新的绘图。 使用lineslines添加到现有图。

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)
}

在此处输入图片说明

您也可以使用ggplot2做到这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()

在此处输入图片说明

使用ggplot2

 x = seq(from = 0,to = 14,length.out = 100)

        p <- ggplot(data=data.frame(x), aes(x = x,y = sin(x + 1 * .5)*(7 - 1) ))+geom_line()

        for (i in 2:6) {

           p <- p + geom_line(aes_string(y = sin(x + i * .5)*(7 - i)),col  = i)+
                      theme_classic()+theme(axis.title.y = element_blank())

         }
       p

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM