簡體   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