-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraries (R).Rmd
54 lines (39 loc) · 2.01 KB
/
Libraries (R).Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: Libraries (R).ipynb
output: html_document
---
# Libraries
Instead of inventing everything from ground up, developers use software libraries (or packages) to utilise commonly used functionalities.
Libraries have functions (in some programming languages, methods) which take an input and conduct operations to achieve the expected output.
The input is series of parameters described in the method documentation, a written text which spesifies how the library should be used.
## Installing libraries
Before you can use a library, it needs to be installed into your system.
We now install [ggplot2](https://ggplot2.tidyverse.org/), a popular library for plotting data.
```{r}
install.packages("ggplot2", repos = "http://cran.us.r-project.org") ## this installs the package to your computer
```
## Taking the library into use
After an library has been installed, you need to take it into use: state that you want to use this library.
After that you can use the functions spesified in [the documentation](https://ggplot2.tidyverse.org/reference/index.html).
Often documentation is supplemented by [examples](https://ggplot2.tidyverse.org/#usage) and for often used libraries, Google will also prove answers to many more spesific questions.
The library includes a dataset `mpg` including details on the fuel econonomy of various cars ([see more](https://ggplot2.tidyverse.org/reference/mpg.html)).
We use it in the next examples to have an easy to use dataset available for these exercises.
```{r}
library(ggplot2)
```
```{r}
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()
```
```{r}
head( mpg )
```
```{r}
## using geom_bar to produce bar chart
ggplot( mpg , aes( manufacturer ) ) +
geom_bar()
```
# Exercises
* Visualise the various transistion models of cars in `mpg` using a bar chart.
* Visualise the production years of the cars in `mpg` using [a histogram](https://ggplot2.tidyverse.org/reference/geom_histogram.html).
* Visualise the production years per model of the cars in `mpg` using a frequency polygon.