Rsquared Academy Blog

Explore..Discover..Learn

Readable Code with Pipes

Introduction R code contain a lot of parentheses in case of a sequence of multiple operations. When you are dealing with complex code, it results in nested function calls which are hard to read and maintain. The magrittr package by Stefan Milton Bache provides pipes enabling us to write R code that is readable. Pipes allow us to clearly express a sequence of multiple operations by: structuring operations from left to right avoiding nested function calls intermediate steps overwriting of original data minimizing creation of local variables Pipes If you are using tidyverse, magrittr will be automatically loaded.

Introduction to tibbles

Introduction A tibble, or tbl_df, is a modern reimagining of the data.frame, keeping what time has proven to be effective, and throwing out what is not. Tibbles are data.frames that are lazy and surly: they do less (i.e. they don’t change variable names or types, and don’t do partial matching) and complain more (e.g. when a variable does not exist). This forces you to confront problems earlier, typically leading to cleaner, more expressive code.

Importing Data into R - Part 3

Introduction This is the third post in the series Importing Data into R. You can find the link to the previous posts below: Importing Data into R - Part 1 Importing Data into R - Part 2 In the previous post, we explored reading data from excel spreadsheets and files from other statistical softwares such as SAS, SPSS and STATA. In this post, we will learn to read data from:

Importing Data into R - Part 2

Introduction This is the second post in the series Importing Data into R. In the previous post, we explored reading data from flat/delimited files. In this post, we will: list sheets in an excel file read data from an excel sheet read specific cells from an excel sheet read specific rows read specific columns read data from - SAS - SPSS - STATA Libraries, Data & Code We will use the readxl package.

Importing Data into R - Part 1

Introduction This is the first post in the series Importing Data into R. Before we get started, let me talk a bit about what we will learn in this series. I am planning to write 3 posts in which we will explore how to read data from: flat/delimited files (.csv, .txt, .tsv) excel spreadsheets (.xls, .xlsx) statistical softwares JSON/XML There are other ways to get data into R such as databases, APIs etc.

Legend - Part 3

Introduction This is the 15th post in the series Elegant Data Visualization with ggplot2. In the previous post, we learnt how to modify the legend of plots when aesthetics are mapped to variables.If the aesthetics are mapped to variables, ggplot2 automatically creates legends wherever applicable. You may want to modify the appearance of legends. In this module, we will learn to modify the legends when shape is mapped to categorical variables.

Legend - Part 4

Introduction This is the 16th post in the series Elegant Data Visualization with ggplot2. In the previous post, we learnt how to modify the legend of plot when shape is mapped to categorical variables.If the aesthetics are mapped to variables, ggplot2 automatically creates legends wherever applicable. You may want to modify the appearance of legends. In this module, we will learn to modify the legends when size is mapped to categorical variables.

Legend - Part 5

Introduction This is the 17th post in the series Elegant Data Visualization with ggplot2. In the previous post, we learnt how to modify the legend of plot when size is mapped to continuous variable.If the aesthetics are mapped to variables, ggplot2 automatically creates legends wherever applicable. You may want to modify the appearance of legends. In this module, we will learn to modify the legends when alpha is mapped to categorical variables.

Legend - Part 6

Introduction This is the 18th post in the series Elegant Data Visualization with ggplot2. In the previous post, we learnt how to modify the legend of plot when alpha is mapped to a categorical variable. In this post, we will learn to modify legend title label and bar Libraries, Code & Data We will use the following libraries in this post: readr ggplot2 All the data sets used in this post can be found here and code can be downloaded from here.

A Complete Guide to Importing Data into R - Part 3

Introduction This is the fifth post in the series Data Wrangling with R. In the previous post, we learnt to import data from flat files, excel spreadsheets and statistical softwares. In this post, we will learn to import data from: JSON XML Libraries, Data & Code We will use the following libraries in this post: jsonlite xml2 XML purrr All the data sets used in this post can be found here and code can be downloaded from here.