theme_avalanche_h()
.library(ggplot2) theme_minimal(base_size = 14) + theme(panel.grid.minor = element_blank(), panel.grid.major.y = element_blank())
residents_per_sector <- data.frame( sector = as.factor(1:8), residents = c(1000, 2034, 4594, 2304, 8093, 1200, 300, 2398) ) ggplot(residents_per_sector, aes(forcats::fct_reorder(sector, residents), residents)) + geom_col() + coord_flip() + xlab("sector") + theme_avalanche_h()
use_r()
called "db_con"db_con <- function(dbname = "residents_per_sector") { dbname <- match.arg(dbname) # We'll pretend we've connected to a database # and just return some hard-coded data instead. data.frame( sector = as.factor(1:8), residents = c(1000, 2034, 4594, 2304, 8093, 1200, 300, 2398) ) }
load_all()
to load the package function.ggplot( db_con(), aes(forcats::fct_reorder(sector, residents), residents) ) + geom_col() + coord_flip() + xlab("sector")
R/themes.R
to use ggplot2::
instead of library(ggplot2)
use_package("ggplot2")
to add ggplot2 to Imports
Cmd/Ctrl+Shift+L
) and run this code to make sure it works:ggplot( db_con(), aes(forcats::fct_reorder(sector, residents), residents) ) + geom_col() + coord_flip() + xlab("sector") + theme_avalanche()
use_roxygen_md()
use_tibble()
and use_data_table()
R/get_data.R
, edit the function to be able to return a data table: Add the argument data_table = FALSE
. If data_table
is TRUE
, convert the data frame with data.table::as.data.table()
res_data <- get_resident_data(data_table = TRUE) stopifnot(data.table::is.data.table(res_data)) res_data
Finish early? Try this stretch goal:
Run use_pipe()
to add the magrittr pipe to your package. What changed?
use_r()
; load the functions with load_all()
; build the package with build()
use_package()
and use the format pkg::fun()
to call functions from other packagesAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.