Draw Multiple Function Curves to Same Plot | Base R & ggplot2 Package | Using curve() & geom_line()

preview_player
Показать описание
R code of this video:

my_fun1 <- function(x) { x^3 - x * 300 } # Create own functions
my_fun2 <- function(x) { x^3 * 2 + x^2 + x * 10 + 5 * 10^10 }
my_fun3 <- function(x) { - x^3 + x^2 - 2 * 10^10 }

curve(my_fun1, from = - 5000, to = 5000, col = 2) # Draw Base R plot
curve(my_fun2, from = - 5000, to = 5000, col = 3, add = TRUE)
curve(my_fun3, from = - 5000, to = 5000, col = 4, add = TRUE)

library("ggplot2")

values = c(my_fun1(- 5000:5000),
my_fun2(- 5000:5000),
my_fun3(- 5000:5000)),
fun = rep(c("fun1", "fun2", "fun3"), each = 10001))

ggplot(data_fun, # Draw ggplot2 plot
aes(x, values, col = fun)) +
geom_line()

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Great one! could you make a video on how to plot multiple different interactive plots in R (around 10) using plotly. Also is there a way to get some sort of table info next to each plot specifying information about the plots from the datasets. Thanks!

janet