I am working my way through DataCamp's ggplot2 tutorial. I keep getting the above error when I try to run this code. It will run on their Console, and will run in RStudio, but will not run in Jupyter. Any thoughts. I get the "plot.new has not been called yet" error after the abline code, and the lapply code.
# Basic plot
mtcars$cyl <- as.factor(mtcars$cyl)
plot(mtcars$wt, mtcars$mpg, col = mtcars$cyl)
# Use lm() to calculate a linear model and save it as carModel
carModel <- lm(mpg ~ wt, data = mtcars)
# Call abline() with carModel as first argument and lty as second
abline(carModel, lty = 2)
# Plot each subset efficently with lapply
# You don't have to edit this code
lapply(mtcars$cyl, function(x) {
abline(lm(mpg ~ wt, mtcars, subset = (cyl == x)), col = x)
})
I am working my way through DataCamp's ggplot2 tutorial. I keep getting the above error when I try to run this code. It will run on their Console, and will run in RStudio, but will not run in Jupyter. Any thoughts. I get the "plot.new has not been called yet" error after the abline code, and the lapply code.