-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts_scatter-plot.Rmd
50 lines (41 loc) · 1.55 KB
/
charts_scatter-plot.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
---
title: "Charts: Scatter plot"
output:
html_document:
toc: true
toc_float:
collapsed: false
includes:
before_body: [includes/include_header.html, includes/include_header_navpage.html]
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
eval = TRUE,
echo = FALSE,
message = FALSE,
warning = FALSE
)
```
# What is a scatter plot?
Scatter plots are very simple visualisations that allow viewers to compare the correlation between two variables, typically between multiple groups of data. Scatterplots may also include trendlines for comparison purposes, however the inclusion of error bars complicates the chart sufficiently to be counted as a separate type of chart.
Required Data:
- x coordinates: traditionally this is the independent variable, for instance the year a measurement is taken.
- y coordinates: traditionally this is the dependent variable, for instance the value of a measurement in a specific year.
Below is a minimal example of a scatter plot using `R` and the `highcharter` library:
```{r}
library("tidyverse")
library("gapminder")
library("highcharter")
gapminder %>%
group_by(continent, year) %>%
mutate(median.life.exp = median(lifeExp)) %>%
select(continent, year, median.life.exp) %>%
unique() %>%
hchart(type = "scatter",
hcaes(x = year, y = median.life.exp, group = continent)) %>%
hc_yAxis(title = list(text = "Median Life Expectancy")) %>%
hc_subtitle(text = "Data from library(gapminder)") %>%
hc_size(width = "100%", height = "300px")
```