Warning in install.packages

Please help, I am a beginner just learning data science from the scratch, I just started learning the rudiments of Rstudio and I tried to install the package "ggplot2" using install.packages('ggplot2') but I keep getting this error message:

Warning in install.packages :
package ‘install.packages('ggplot2')’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at

install.packages("library(ggplot2)")

What version of R are you running? If it is very old, you can get this warning.
Run the command

sessionInfo()

to see your version of R.

You can't combine those two commands in that way, they are meant to be run separately.

The correct command for installing ggplot2 is

install.packages("ggplot2")

After a successful installation, you have to load the package in your session with this other command

library(ggplot2)

Thank you, I'm running the latest version of R 4.1.2

Did you run

install.packages("library(ggplot2)")

or

install.packages("ggplot2")

As @andresrcs pointed out, the latter is the correct one.

I used install.packages("ggplot2") I only used the library command to see if I had it installed already but I'm just so confused.

What I did now is I navigated to the package Icon in the lower right quadrant, scrolled down till I found ggplot2 then I ticked the box just by the left of (ggplot2) package. I'm not sure if it worked but there were a lot of red lines downloading some stuff line after line all in kilobytes.

If ggplot2 appears in the Packages pane, then it is installed. Selecting it there should not result in the stream of red output that you describe but let's ignore that for the moment. Try running the two commands

library(ggplot2)
search()

Here is the output I get from that in a new RStudio session

[1] ".GlobalEnv"        "package:ggplot2"   "tools:rstudio"    
 [4] "package:stats"     "package:graphics"  "package:grDevices"
 [7] "package:utils"     "package:datasets"  "package:methods"  
[10] "Autoloads"         "package:base"     

You can see package:ggplot2 in the list, showing that ggplot2 is loaded. Your output may look different but you should see ggplot2 listed if you successfully installed it and then ran library(ggplot2).

Thank you so much this worked perfectly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.