Similar seaborn plot in R

时间:2017-12-18 05:55:38

标签: r plot ggplot2

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

2 个答案:

答案 0 :(得分:5)

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

enter image description here

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

enter image description here

答案 1 :(得分:0)

Using the ggplot2

app.service('fileUpload', ['$http', function ($http) {