Some basic data preparation was required to correct the data type for the OFFENCE_MONTH field, and to select a subset of fields that are required for this analysis. I am using the tidyverse package for loading and manipulating the data set. The data set used for this post is the same NSW Roads Offences and Penalties data that I used in my previous posts for exploring the use of PowerBI and Tableau for building data visualisations and stories. The process I followed is summarised in the table of content for this R Markdwon file. Once you have created the rmd file, you now ready to start writing code to perform the usual data preparation and exploration activities.Īll the code used to prepare for this blog post is published as an R Markdown on rpubs at this link. Typically this will be done in an R integrated development environment such as RStudio, a tool that most data scientists are familiar with. To get started with R Markdown (rmd), the user must create an R Markdown, or a Notebook file. In this blog post I will be exploring the use of R Markdown with ggplot to produce visualisations and communicate data insights. It implements a Grammar of Graphics as a scheme for data visualization which breaks up graphs into semantic components such as scales and layers. Ggplot is a data visualization package for the statistical programming language R. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents that can be used to document and share the results of data processing and analysis including visualisations with others. The document contains chunks of embedded R code and content blocks. R Markdown is a file format for creating dynamic documents with R by writing in markdown language. # Africa sunburst(data = data.Using R markdown and ggplots for data visualisation Just pick five colors for the two inner most rings of the sunburst plot and it’ll shuffle the rest of the colors. I wouldn’t recommend trying to pick a color for each role or name it becomes too unweildy. Moreover, by presenting the data by continent, you can focus on just five specific color as you decide on a palette. Ultimately, I found the information best presented by continent as the base of the sunburst plot, followed by category, specific roles and the names of each of the 100 women honored by the BBC. ))) %>% filter(continent='Asia') %>% mutate( path = paste(continent, category, role, name, sep = "-") ) %>% slice(2:100) %>% mutate( V2 = 1 ) Sunburst: Africa ))) %>% filter(continent='Africa') %>% mutate( path = paste(continent, category, role, name, sep = "-") ) %>% slice(2:100) %>% mutate( V2 = 1 ) # Filter for Asia asia_name % select(continent, category, role, name) %>% # remove dash within dplyr pipe mutate_at(vars(3, 4), funs(gsub("-", "". women % mutate(continent = NA) # add continents to women dataframe women$continent % select(continent, category, role, name) %>% # remove dash within dplyr pipe mutate_at(vars(3, 4), funs(gsub("-", "". The data is from week 50 of TidyTuesday, exploring the BBC’s top 100 influential women of 2020. library(tidyverse) library(sunburstR) Load Data & Explore There are other packages for sunburst plots including: plotly and ggsunburst (of ggplot), but we'll explore sunburstR in this post. The two main libraries are tidyverse (mostly dplyr so you can just load that if you want) and sunburstR. For interactive visuals, you’ll want to use RMarkdown. The following code can be run in RMarkdown or an R script. The original document is written in RMarkdown, which is an interactive version of markdown. This is a quick walk through of using the sunburstR package to create sunburst plots in R.
0 Comments
Leave a Reply. |