I got the exactly the same graph after input the code you provided. Does it mean ggplot2 installed succesfully?
Beside, I want to ask why you didn't write code like x=displ, y= hwy. What is mpg? I know your code is a combination to create a graph with x,y and colored with geom_point() to add a layer.
works just as well as the positional arguments (displ, the x-axis comes first, hwy, the y-axis second). It's a matter of taste; I probably usually make it explicitly more often than not.
Looks like you've grasped the basic idea, which is building layers. Have fun!
One more question followed, the code run out the graph at first time, after couple of hours, the graph dosen't run out again, but the code shows correct in console.
Do you have ways to solve the graph run out barriers? After I could control the graph, I will be able to add things by codes and see the changes in graph.
This is a different question and is no longer about package installation, please ask it on a new topic providing a relevant REPRoducible EXample (reprex) for this new issue.
@andresrcs is suggesting a helpful practice--a new topic for when the question changes. In this case, as he points out, we've moved beyond installation into how to use the ggplot2 package, and people who have that question aren't likely to be looking under installation. So, please do post as a new question with a reproducible example, called a reprex .
On the other hand, while you're doing that, I'll take a guess about what may be happening.
opens a viewer window and displays the graphical result. If you close the window, you have to run the code again. That gets tedious, so you can create an object to be able to display the graph any time. (You can also save an image to file with ggsave().)
library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()
p