eds221-day10-compmy_ggplot_theme.Rmdtidyverse and palmerpenguins packagestheme() component (you can make it as bright / awful as you want - this is going to become a ggplot theme you can share with the world, so it’s up to you)Here’s something awful just to remind you of what this can look like:
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point() +
theme(title = element_text(size = 16, color = "purple"),
plot.background = element_rect(fill = "black"),
panel.background = element_rect(fill = "gray20"),
axis.text = element_text(color = "yellow"),
panel.grid.major = element_line(color = "blue"),
panel.grid.minor = element_line(color = "cyan")
)
theme() component of your customized ggplot graph that you just made into your empty R script. For the example above, that would just be:theme(title = element_text(size = 16, color = "purple"),
plot.background = element_rect(fill = "black"),
panel.background = element_rect(fill = "gray20"),
axis.text = element_text(color = "yellow"),
panel.grid.major = element_line(color = "blue"),
panel.grid.minor = element_line(color = "cyan")
)
theme_eighties <- function() {theme(title = element_text(size = 16, color = "purple"),
plot.background = element_rect(fill = "black"),
panel.background = element_rect(fill = "gray20"),
axis.text = element_text(color = "yellow"),
panel.grid.major = element_line(color = "blue"),
panel.grid.minor = element_line(color = "cyan")
)
}
R folder (e.g. this one would be theme_eighties.R)devtools::document() to produce the R documentation for your new functionFor example, if mine is called tacopika:
library(tacopika)
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point() +
theme_eighties()
devtools::install_github("username/reponame")We’ve made a number of ggplot graphs, but we haven’t made any tables. Let’s learn one way!
eds221-day10-comp R Project, create a new R Markdown documenttidyverse & kableExtra (note: there are a bunch of ways to make nice tables in R - see David Keyes’ post on How to make beautiful tables in R for more options)datapasta Add-in to create a tibble stored as whale_sightings| date | site | spp | dist_m | behavior |
|---|---|---|---|---|
| 8/12/2014 | channel | unknown | 400 | breach |
| 8/13/2014 | channel | gray | 200 | spout |
| 8/15/2014 | harbor | gray | 60 | spout |
| 8/16/2014 | channel | humpback | 300 | feeding |
| 8/16/2014 | channel | gray | 150 | feeding |
With kableExtra:
# Bootstrap theme
dt %>%
kable(col.names = c("Date", "Site", "Species", "Distance (m)", "Behavior")) %>%
kable_styling(full_width = FALSE, bootstrap_options = "striped")
| Date | Site | Species | Distance (m) | Behavior |
|---|---|---|---|---|
| 8/12/2014 | channel | unknown | 400 | breach |
| 8/13/2014 | channel | gray | 200 | spout |
| 8/15/2014 | harbor | gray | 60 | spout |
| 8/16/2014 | channel | humpback | 300 | feeding |
| 8/16/2014 | channel | gray | 150 | feeding |
# Paper theme
dt %>%
kable() %>%
kable_classic()
| date | site | spp | dist_m | behavior |
|---|---|---|---|---|
| 8/12/2014 | channel | unknown | 400 | breach |
| 8/13/2014 | channel | gray | 200 | spout |
| 8/15/2014 | harbor | gray | 60 | spout |
| 8/16/2014 | channel | humpback | 300 | feeding |
| 8/16/2014 | channel | gray | 150 | feeding |
Check out some other themes and try them out! https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html
A bit more customization:
dt %>%
kable(col.names = c("Date", "Site", "Species", "Distance (m)", "Behavior")) %>%
kable_classic() %>%
column_spec(1, bold = TRUE, background = "yellow") %>%
column_spec(2, italic = TRUE, background = "orange") %>%
add_header_above(c(" " = 1, "One header" = 2, "Another header" = 2)) %>%
scroll_box(height = "100px", width = "500px")
|
One header
|
Another header
|
|||
|---|---|---|---|---|
| Date | Site | Species | Distance (m) | Behavior |
| 8/12/2014 | channel | unknown | 400 | breach |
| 8/13/2014 | channel | gray | 200 | spout |
| 8/15/2014 | harbor | gray | 60 | spout |
| 8/16/2014 | channel | humpback | 300 | feeding |
| 8/16/2014 | channel | gray | 150 | feeding |
See also: DT, reactable, gt, and more!
git_test.Rmd), delete everything below the first code chunk