ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
#> Error in ggplot(data = mpg): could not find function "ggplot"
ggplot(mpg, aes(x=displ,y=hwy))+geom_point()
#> Error in ggplot(mpg, aes(x = displ, y = hwy)): could not find function "ggplot"
I make sure I've already loaded the ggplot2 package using library(ggplot2)
. When I run these two code lines in R script it does work and I can see the plot generated in viewer. But when I use reprex to run these two code lines it shows error like above (I do this because I wanna use reprex to run them and paste the results to stack overflow to ask a question about what the difference between the two code lines is). I wanna know why it shows error in reprex.