library(ggplot2)
data <- data.frame(
x = seq(-3, 7, by = 0.04), # Range nilai x
y = sapply(seq(-3, 7, by = 0.04), function(x) x^2), # Fungsi f(x) = x^2
dy = sapply(seq(-3, 7, by = 0.04), function(x) 2 * x) # Turunan f'(x) = 2x
)
plot <- ggplot(data, aes(x, y)) +
geom_line(aes(color = "f(x)")) +
geom_line(aes(x, dy, color = "f'(x)")) +
labs(title = "Slice Plot: f(x) = x^2 and f'(x) = 2x", x = "x", y = "y") +
scale_color_manual(values = c("f(x)" = "orange", "f'(x)" = "yellow"))
print(plot)