library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# loads relevant syntax as well as ggplot2 packages
library(wesanderson)
library(ggridges)
library(scales)
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
dat <- iris
glimpse(dat)
## Rows: 150
## Columns: 5
## $ Sepal.Length <dbl> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.…
## $ Sepal.Width <dbl> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.…
## $ Petal.Length <dbl> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.…
## $ Petal.Width <dbl> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.…
## $ Species <fct> setosa, setosa, setosa, setosa, setosa, setosa, setosa, s…
show_col(wes_palettes$GrandBudapest2)
my_cols <- c(wes_palettes$GrandBudapest2)
# basic example
p1 <- ggplot(dat) +
aes(x = Sepal.Length, y = Species, fill = Species) +
geom_density_ridges() +
theme_ridges() +
theme(legend.position = "none")
p1 + scale_fill_manual(values = my_cols)
## Picking joint bandwidth of 0.181
## Make an interactive plot where points can be animated for more information Using interactive graphing with the plotly function
p2 <- ggplot(dat) +
aes(x = Sepal.Length, y = Petal.Length, col = Species) +
geom_point() + geom_smooth() + xlab("Sepal Length") +
ylab("Sepal Width")
p2 + scale_fill_manual(values = my_cols)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
ggplotly(p2)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'