简体   繁体   中英

Similar seaborn plot in R

i want experimenting all plots in seaborn with R for that i want plot similar seaborn plot in R but i am unable to fulfill the exact similar graph in R seaborn graph

my updated R code is

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

Your code is creating a new plot each time through the loop. Use lines to add a line to an existing plot.

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

在此处输入图片说明

You could also do this with 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()

在此处输入图片说明

Using the 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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