Why does the following function draw a base R plot but not the GGplot equivalent?
(Base R call commented out)
library(ggplot2)
library(dplyr)
test <- function() {
data <- data.frame("x"=1:10, "y"=1:20)
mean <- mean(data$x)
# Gplot, doesn't work
data %>%
ggplot( aes(x=x, y=y)) +
geom_line() +
geom_point()
# base R plot, does work
#plot(data$x, data$y)
return(mean)
}
test()