Перед тим як почати


Figure 1

RStudio extends what R can do, and makes it easier to write R code and interact with R.

Figure 2

automatic car gear shift representing the ease of RStudio

Figure 3

Скріншот запуску RStudio _

Figure 4

Приклад структури робочого каталогу

Figure 5

Скріншот панелі пакетів

Figure 6

Скріншот вікна встановлення пакетів

Введення до R


Починаємо з даних


Figure 1

датафрейм розміром 3 на 3 зі стовпцями, що містять числові, текстові та логічні значення.

Figure 2

Monsters at a fork in the road, with signs saying here, and not here. One direction, not here, leads to a scary dark forest with spiders and absolute filepaths, while the other leads to a sunny, green meadow, and a city below a rainbow and a world free of absolute filepaths. Art by Allison Horst
Image credit: Allison Horst

Figure 3

Yes/no bar graph showing number of individuals who are members of irrigation association

Figure 4

Bar plot of association membership, showing missing responses.

Figure 5

bar graph showing number of individuals who are members of irrigation association, including undetermined option

Маніпулювання даними за допомогою пакету dplyr


Маніпулювання даними за допомогою пакету tidyr


Figure 1

R for Data Science, Wickham H and Grolemund G (https://r4ds.had.co.nz/index.html) © Wickham, Grolemund 2017 This image is licenced under Attribution-NonCommercial-NoDerivs 3.0 United States (CC-BY-NC-ND 3.0 US)


Figure 2

Розташування даних у довгому та широкому форматах головним чином впливає на зручність перегляду. Візуально вам може більше подобатися “широкий” формат, оскільки на екрані можна побачити більше даних. Проте всі функції R, які ми використовували досі, очікують, що дані будуть у “довгому” форматі. Це пояснюється тим, що довгий формат легше сприймається машиною і ближчий до формату баз даних.


Figure 3

Дві таблиці, показані поруч. Перший рядок лівої таблиці виділено синім, а перші чотири рядки правої таблиці також виділено синім, щоб показати, як кожне значення з 'items owned' отримало окремий рядок за допомогою функції separate_longer_delim(). Стовпець 'items owned logical' виділено жовтим у правій таблиці, щоб показати, як функція mutate додає новий стовпець.

Figure 4

Дві таблиці, показані поруч. Стовпець 'items owned' виділено синім у лівій таблиці, а назви стовпців виділено синім у правій таблиці, щоб показати, як значення зі стовпця 'items owned' стають назвами стовпців у результаті функції pivot_wider. Стовпець 'items owned logical' виділено жовтим у лівій таблиці, а значення стовпців bicycle, television і solar panel виділено жовтим у правій таблиці, щоб показати, як значення стовпця 'items owned logical' стали значеннями цих трьох стовпців.

Візуалізація даних за допомогою ggplot2


Figure 1


Figure 2


Figure 3


Figure 4

Scatter plot of number of items owned versus number of household members.

Figure 5

Scatter plot of number of items owned versus number of household members, with transparency added to points.

Figure 6

Scatter plot of number of items owned versus number of household members, showing jitter.

Figure 7

Scatter plot of number of items owned versus number of household members, with jitter and transparency.

Figure 8

Scatter plot of number of items owned versus number of household members, showing points as blue.

Figure 9


Figure 10

Previous plot with dots colored by village.

Figure 11

Scatter plot showing positive trend between number of household members and number of items owned.

Figure 12

Box plot of number of rooms by wall type.

Figure 13

Previous plot with dot plot added as additional layer to show individual values. Boxplot layer is transparent.

Figure 14


Figure 15

Box plot of number of livestock owned by wall type, with dot plot added as additional layer to show individual values.

Figure 16

Previous plot with dots colored based on whether respondent was a member of an irrigation association.

Figure 17

Bar plot showing counts of respondent wall types.

Figure 18

Stacked bar plot of wall types showing each village as a different color.

Figure 19

Bar plot of respondent wall types with each village as a separate bar.

Figure 20

Side by side bar plot showing percent of respondents in each village with each wall type.

Figure 21

Bar plot showing percent of respondents in each village who were part of association.

Figure 22

Previous plot with plot title and labells added.

Figure 23

Bar plot showing percent of each wall type in each village.

Figure 24

Bar plot showing percent of each wall type in each village, with black and white theme applied.

Figure 25

Multi-panel bar chart showing percent  of respondents in each village and who owned each item, with no grids behid bars.

Figure 26


Figure 27


Figure 28

Multi-panel bar charts showing percent of respondents in each village and who owned each item, with grids behind the bars.

Figure 29


Getting started with R Markdown (Optional)


Figure 1

R Markdown wizard monsters creating a R Markdown document from a recipe. Art by Allison Horst
Image credit: Allison Horst

Figure 2

Screenshot of the New R Markdown file dialogue box in RStudio

Figure 3

The 'knitting' process: First, R Markdown is converted to Markdown, which is then converted (via pandoc) to .html, .pdf, .docx, etc.

Figure 4


Figure 5

I made this plot while attending an awesome Data Carpentries workshop where I learned a ton of cool stuff!
I made this plot while attending an awesome Data Carpentries workshop where I learned a ton of cool stuff!

Обробка даних JSON (необов'язково)