In this post, we will learn how to make simple barplot using ggplot2 and learn to reorder barplots in R. We will make a barplot using ggplot2’s geom_col() with multiple bars. By default, ggplot2 orders the bars in alphabetical order. We will see examples of reordering barplots by another numerical variable in the data using… Continue reading Simple Barpots and reordering bars in R
Category: rstats101
3 ways to rank numbers with tidyverse
In this tutorial, we will learn 3 ways to rank integers in tidyverse. Tidyverse’s dplyr has three integer ranking functions, row_number(), min_rank(), and dense_Rank(), inspired by SQL. And these integer ranking functions differ in how they handle ties. Let us jump into simple examples as given by dplyr and create tibble with a sorted column… Continue reading 3 ways to rank numbers with tidyverse
Compute rowwise mean and standard deviation
In this post, we will learn how to compute row-wise summary statistics like mean and standard deviation using dplyr’s row_wise() function. First, let us load tidyverse and verify the version of dplyr. Let us create a toy dataframe with five columns. We use sample() function to create some random vector. And then use matrix() function… Continue reading Compute rowwise mean and standard deviation
Simple linear regression with tidyverse
In this tutorial we will learn how to perform simple linear regression between two numerical variables in R using lm() function. The resulting object from a linear regression analysis using lm() is unwieldy and not intuitive for beginners. We use broom package that is part of tidymodels to make the messy output from lm() into… Continue reading Simple linear regression with tidyverse
How to apply a function on multiple columns using across()
In this post, we will learn how to compute one or multiple functions on multiple columns using dplyr’s across() function. dplyr’s across() function can be used with summarize() or mutate() functions to operate on columns. In this example we will use summarize() function to compute mean values of multiple columns at the same time using… Continue reading How to apply a function on multiple columns using across()