calculate lim function with plot in R

2019-09-02 15:08发布

问题:

Say there is lim (\lim_{x \to \infty}\left(\frac{x}{x - 1} - 2\right) )

it is =-1. How can i get plot with this value is indicated? To be more clearly i want plot like this

how to get it?

回答1:

You can do something like this:

my_func <- function(x) x / (x - 1) - 2

library(ggplot2)
ggplot(data.frame(x = 0), aes(x)) +
    stat_function(fun = my_func, aes(colour = "Function")) +
    geom_hline(aes(yintercept = -1, colour = "Asymptote")) +
    scale_colour_manual(values = c("Asymptote" = "blue", "Function" = "orange")) + 
    xlim(-10, 10) +
    theme_minimal()



标签: r ggplot2