Follow our Facebook page or our developer’s Twitter for more tutorials and future updates.
The tutorial is based on R and StatsNotebook, a graphical interface for R.
Line chart can be used to show the evoluation of numeric variables. StatsNotebook uses geom_line()
from ggplot2
to build line chart.
We use the built-in Human Development Index dataset in this example. This dataset can be loaded into StatsNotebook using instruction here. This is a data from the United Nations Development Programmes (UNDP).
We will use line chart to visualise the evolution of Human Development Index from 1990 to 2018 across six regions. This dataset contains the following variables
This dataset can also be loaded using the following codes
library(tidyverse)
currentDataset <- read_csv("https://statsnotebook.io/blog/data_management/example_data/HDI.csv")
This data is in wide format
And we will need to reshape it to a long format.
There will be only 4 variables after reshaping the data.
In this example, we will visualise the evolution of Human Development Index across six world regions.
currentDataset %>%
drop_na(Region) %>%
ggplot(aes(y = HDI, x = Year, color = Region)) +
geom_line(na.rm = TRUE, size = 1)+
scale_fill_brewer(palette = "Set2")+
scale_color_brewer(palette = "Set2")+
theme_bw(base_family = "sans")+
theme(legend.position = "bottom")
"Chan, G. and StatsNotebook Team (2020). StatsNotebook. (Version 0.1.0) [Computer Software]. Retrieved from https://www.statsnotebook.io"
"R Core Team (2020). The R Project for Statistical Computing. [Computer software]. Retrieved from https://r-project.org"
"Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org"
Follow our Facebook page or our developer’s Twitter for more tutorials and future updates.