Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in library(ggplot2) : There is no package called 'ggplot2'

Tags:

r

ggplot2

I'm new to R and I'm just trying to get through some tutorials.

When I try installing ggplot2, I get this error.

Error in library(ggplot2) : There is no package called 'ggplot2'

I tried these in R and RStudio.

install.packages("ggplot2", dep=T)

install.packages('ggplot2', repos='http://cran.us.r-project.org')

remove.packages("ggplot2")

but I get the error

(Error in remove.packages : there is no package called 'ggplot2')

This is what I get from install.packages("ggplot2")

> install.packages("ggplot2")
Installing package into ‘.../R/win-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
  'lib = ".../R/win-library/3.4"' is not writable
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/ggplot2_2.2.1.zip'
Content type 'application/zip' length 2784566 bytes (2.7 MB)
downloaded 2.7 MB

package ‘ggplot2’ successfully unpacked and MD5 sums checked
Warning in install.packages :
  cannot remove prior installation of package ‘ggplot2’

The downloaded binary packages are in
    C:...\AppData\Local\temp\RtmpqaGNpr\downloaded_packages

I removed all ggplot2 files manually then tried to install again. Here's my result.

> install.packages("ggplot2")
Installing package into ‘.../R/win-library/3.4’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://ftp.osuosl.org/pub/cran/bin/windows/contrib/3.4/ggplot2_2.2.1.zip'
Content type 'application/zip' length 2784566 bytes (2.7 MB)
downloaded 2.7 MB

package ‘ggplot2’ successfully unpacked and MD5 sums checked
Warning: unable to move temporary installation ‘...\R\win-library\3.4\file26b43a54980\ggplot2’ to ‘...\R\win-library\3.4\ggplot2’

The downloaded binary packages are in
        C:...\AppData\Local\temp\Rtmpq0T9a6\downloaded_packages
> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’
> library("ggplot2")
Error in library("ggplot2") : there is no package called ‘ggplot2’

These code was run using R 3.4.2

like image 909
manderson Avatar asked Oct 16 '17 15:10

manderson


4 Answers

Steps

  1. Go To Tools

  2. Install Packages

  3. In Packages Text Box Type ggplot2

  4. Check the checkbox install dependencies

like image 98
Santhosh Avatar answered Oct 19 '22 03:10

Santhosh


You need to update your R version and do this but you'll need install all packages again:

Tool > Global Options > R version (CHANGE) > Select "Use your machine's default version of R..."

like image 38
andhherson Avatar answered Oct 19 '22 02:10

andhherson


When having this issue I would suggest :

  • try turning it off and on again
  • update R to last version if possible
  • remove manually all the folders related to the relevant package and retry the installation
  • change your default library location : How do you change library location in R?
like image 1
Moody_Mudskipper Avatar answered Oct 19 '22 02:10

Moody_Mudskipper


Try launching R client directly from command prompt, then issue the instruction: install.packages("ggplot2", lib="C:/Users/YourUser/Documents/R/win-library/3.3")

like image 1
Renaud Avatar answered Oct 19 '22 02:10

Renaud