Skip to content

Instantly share code, notes, and snippets.

@ericnovik
Last active October 17, 2018 03:04
Show Gist options
  • Save ericnovik/52736564c49d36706de21cf35db3341c to your computer and use it in GitHub Desktop.
Save ericnovik/52736564c49d36706de21cf35db3341c to your computer and use it in GitHub Desktop.
library(cowplot)
library(tidyverse)
pow <- function(x, p) sign(x) * abs(x)^p
n <- 1e3; num_of_curves <- 10;
x <- seq(-3, 3, length.out = n)
C <- seq(-4, 4, length.out = num_of_curves)
C <- c(C, 0) # include the C = 0 solution
ncol <- length(C)
y <- matrix(nrow = n, ncol =ncol)
for (i in 1:ncol) {
y[, i] <- pow((x^3 + C[i]), 1/3)
}
df <- as_tibble(y)
df %<>%
mutate(x) %>%
gather(curve, y, -x)
qplot(x, y, data= df, geom = "line", color = curve) +
geom_hline(yintercept = 0, size = 0.1) +
geom_vline(xintercept = 0, size = 0.1) +
theme(legend.position = "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment