I leraned ggplot2 for scatter plots from "ggplot2: The Elements for Elegant Data Visualization in R". It is unable to draw a
regression line with the qplot() function in the recent version of ggplot2. I used the following code to draw a scatter plot.
p <- ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) +
geom_point() +
geom_smooth(method=lm, se=FALSE, fullrange=TRUE)+
theme_classic()
# Use brewer color palettes
p+scale_color_brewer(palette="Dark2")
The outcome graph supposed to be Figure 1, but I got Figure 2. Where is the lines of x-axis and y-axis? How can I fix it? Mybe I need the old version of ggplot2. I think it would be more easy for me to learn.