-
Notifications
You must be signed in to change notification settings - Fork 1
6. R analyses
library(ggplot2)
data("mtcars")
The most basic syntax to create a ggplot object consists of the following:
- Data
- Aesthetic
- Geometry
mtcars %>%
ggplot(aes(x=cyl, y = mpg)) +
geom_point()
The Tidyverse is a collection of R packages designed to make data manipulation more user-friendly.
Some of these R packages are dplyr, ggplot2, tidyr, etc.
All of these packages will be available to use once you load the library. This can be done as follows:
## Loading the library
library(tidyverse)
To make R code more human-readable, the Tidyverse tools use the pipe %>% to allow the output of a previous command to be used as input to another command. In the example below, we create a vector of numbers and then we pipe it to the function mean().
This pipe operator can be used for all sorts of functions as we will see later.
Numbers <- c(5,10,15,20,25)
Numbers %>%
mean()
When it comes to manipulating data dplyr has many useful functions.
The codeblock below describes a list of the most used by the lab:
## You have a data frame with information about cars. As columns, you have information about price, year, model, gears, and mpg. Each row is the information for different types of cars.
## Extracting columns from a data frame
data <- mtcars %>% # piping data
select(price,year) # selecting only the columns price and year
## Removing a column from a data frame
data <- mtcars %>% # piping data
select(-c(price)) # removing the column price from data frame
Common lab SOPs:
Bioinformatics-related:
Image analyses-related:
Programming-related: