R - ggplot2 설치 오류 해결

ggplot2가 실행 되지 않아 (정확히 말하면 vctrs 패키지 설치 오류) 해결 방법을 공유 합니다.

ggplot2을 아래와 같이 설치 하였습니다.

install.packages("ggplot2")

그리고 아래와 같이 라이브러리를 로드 하였습니다.

하지만, 에러가 나와서 당황했습니다.

> library(ggplot2)
에러: package or namespace load failed for ‘ggplot2’:
 .onLoad가 loadNamespace()에서 'pillar'때문에 실패했습니다:
  호출: utils::packageVersion("vctrs")
  에러: ‘vctrs’이라고 불리는 패키지가 없습니다

패키지가 설치 되지 않았구나… 하고 아래와 같은 명령어로 패키지를 설치하려 했으나, 에러가 납니다.

> install.packages("vctrs")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/YooWS/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/vctrs_0.3.1.zip'을 시도합니다
Warning in install.packages :
  cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/vctrs_0.3.1.zip': HTTP status was '404 Not Found'
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/vctrs_0.3.1.zip'를 열 수 없습니다
Warning in install.packages :
  download of package ‘vctrs’ failed

결국, 패키지를 직접 설치하자! 라는 다짐으로 vctrs 패키지 링크로 점프를 하였습니다. vctrs 0.3.1.zip

해당 페이지에 있는 vctrs를 다운 받은후, 기본 패키지 설치로 복사해 줍니다.

C:\Users[개인이름]\Documents\R\win-library\4.0

다행이 ggplot2라이브러리가 제대로 로딩이 되고 그래프도 잘 표시해 줍니다.

library(ggplot2)
qplot(x)