Please sign up for a function here: https://docs.google.com/spreadsheets/d/1-RWAQTlLwttjFuZVAtSs8OiHIwu6AZLUdWugIHHTWVo/edit?usp=sharing
For this assignment, please submit both the .Rmd
and the
.html
files. I will add it to the website. Remove your name
from the Rmd if you do not wish it shared. If you select a function
which was presented last
year, please develop your own examples and content.
scale_x_reverse()
In this document, I will introduce the scale_x_reverse() function and show what it’s for.
#load tidyverse up
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## âś” ggplot2 3.4.0 âś” purrr 1.0.1
## âś” tibble 3.1.8 âś” dplyr 1.0.10
## âś” tidyr 1.2.1 âś” stringr 1.5.0
## âś” readr 2.1.3 âś” forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## âś– dplyr::filter() masks stats::filter()
## âś– dplyr::lag() masks stats::lag()
library(ggplot2)
#example dataset
library(palmerpenguins)
data(penguins)
scale_x_reverse(), reverses the x axis of the data. Typically the data would be ordered from smallest to largest value, but this function would arrange the data from largest to smallest values. In the example below I’ll show what the plot looks like without the scale_x_reverse() function and then how the plot changes when the function is implemented into the command.
##Example 1: Penguin Data Set
##Plot without scale_x_reverse() function
ggplot(penguins) +
aes(x = body_mass_g,
y = bill_length_mm,
color = species)+
labs(title= "Body Mass (Grams) vs. Bill Length (mm) by Penguin Species", y = "Bill Length (mm)", x = "Body Mass (g)")+
geom_point()
## Warning: Removed 2 rows containing missing values (`geom_point()`).
ggplot(penguins) +
aes(x = body_mass_g,
y = bill_length_mm,
color = species) +
labs(title= "Body Mass (Grams) vs. Bill Length (mm) by Penguin Species", y = "Bill Length (mm)", x = "Body Mass (g)")+
geom_point() +
scale_x_reverse()
## Warning: Removed 2 rows containing missing values (`geom_point()`).
##Example 2: mtcars data set
##Without scale_x_reverse() Function
data("iris")
ggplot(iris) +
aes(x = Petal.Length,
y = Sepal.Length,
color = Species) +
labs(title= "Petal Length vs Sepal Length by Species", y = "Sepal Length", x = "Petal Length")+
geom_point()
##With scale_x_reverse() Function
data("iris")
ggplot(iris) +
aes(x = Petal.Length,
y = Sepal.Length,
color = Species) +
labs(title= "Petal Length vs Sepal Length by Species", y = "Sepal Length", x = "Petal Length")+
geom_point() +
scale_x_reverse()
I think this function could be useful as a different way to view a data set. Maybe it would be easier to use certain correlation patterns with this function. I think it will be a good function to know, but I don’t think it is the best thing since sliced bread.