3 - R packages and plotly

Objectives:
1. Understand what R packages are and what they are used for
2. Know how to install and load an R package, using plotly as an example

1 Why install packages?

In a simple answer, because each of the more than 21,000 R packages has an extension of resources that R itself does not have in its original installation. In other words, it extends the tool for a specific purpose, such as reproducing and even modifying code snippets that result in interactive teaching objects for basic education.
For this, we will use only two packages, plotly and leaflet. This means that the interactivity packages need to be installed before the code can be executed. But don’t worry. This is one of the easiest parts of working with R.

2 Installing the plotly package in R

  1. Go to the Packages tab in RStudio.

  1. Type the name of the package in the field (plotly), and click Install.

Done! The package will be installed from the RStudio cloud server (whether on your computer or in the cloud), with some intermediate messages in red, as shown below.

3 Loading the installed package

R allows you to install a huge number of packages. But of course you won’t use them all at the same time. So R needs to “know” which package you want at any given moment, which is done by the library command, illustrated below for the plot_ly package, as follows:
library(plotly)
Done! Package installed and loaded!
Now it’s time to execute some code snippets for educational purposes.
Back to top