0

I'm using VS code and I am trying to learn the ggplot2 package in R. I installed ggplot2 in the base R console and then from the VS Code editor, as per this post's suggestion: How to install R packages in VS code

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

I then downloaded an external dataset to use it to learn ggplot2:

load(url('https://github.com/matloff/fasteR/blob/master/data/mlb.RData?raw=true'))

Then I tried to assign the output of ggplot2, on the mlb dataset, to a variable:

p <- ggplot2(mlb) 

I get this error:

Error in ggplot2(mlb) : could not find function "ggplot2"

This is happening with other packages as well. For reference, my current directory is: "/Users/saunok/Library/CloudStorage/Dropbox/Areas_of_Responsibility/Programming/R"

The installed packages are being installed in: "/var/folders/hq/lbddkgmd0fbbp1r2lqsp7nkm0000gn/T//RtmpYA5gLR/downloaded_packages"

I tried: To use installed R packages in VS Code I expected: To be able to use the package for analysis Result: R or VS Code is failing to detect the installed packages.

  • 2
    After installing the package, you'll need to load it `library(ggplot2)` – Mako212 Feb 14 '23 at 22:40
  • 1
    Also, the function for a plot is `ggplot()`, not `ggplot2()` – Mako212 Feb 14 '23 at 22:41
  • Thank you - ggplot did the trick. I was following a tutorial where it was ggplot2, and I didn't understand. But the path where ggplot2 was installed - the one given in the post - is different from the path I get from `libPaths()`. Is this the norm? – Saunok Chakrabarty Feb 15 '23 at 15:33

0 Answers0