r - Plot polynomial curve in ggplot using equation, not data points -
this question has answer here:
- equivalent of curve() ggplot 2 answers
is there way plot polynomial function in ggplot without having plot datafame contains selected points along curve of interest? equation x^3 + x^2 + x + 5. thought done in same way geom_abline can used add straight line plot far having no luck finding way this. checked ggplot2 documentation didn't see there thought help. geom_abline doesn't seem extend past straight lines.
my end goal plot data independent dataset , use polynomial curve "reference standard". code below plots curve of interest plotting values along curve, not using equation directly.
x <- 1:100 y <- x^3+x^2+x+5 dat <- as.data.frame(x,y) ggplot(dat, aes(x,y)) + geom_point()
you're looking stat_function()
, think:
x <- 1:100 dat <- data.frame(x,y=x^3+x^2+x+5) f <- function(x) x^3+x^2+x+5 ggplot(dat, aes(x,y)) + geom_point()+ stat_function(fun=f, colour="red")
Comments
Post a Comment