You need dependencies = TRUE
. Exit and re-open RStudio then run this
install.packages("ggplot2", dependencies = TRUE, repos = "http://cran.us.r-project.org")
I usually use pacman
package to manage my packages. It will check if packages are already existed. If not, it will install and load the missing ones
https://cran.r-project.org/web/packages/pacman/vignettes/Introduction_to_pacman.html
Cheers