weimsn / kfbmisc

Home Page:https://kylebutts.github.io/kfbmisc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kfbmisc

kfbmisc is a package full of utility function I find useful

Installation

You can install the development version of kfbmisc from GitHub with:

# install.packages("devtools")
devtools::install_github("kylebutts/kfbmisc")

Utilities

library(kfbmisc)

ggplot2 theme

This is a relatively simple theme that makes the font larger for figures and adds more margins around things.

library(ggplot2)

ggplot(mtcars) +
  geom_point(aes(x = mpg, y = hp)) +
  labs(
    title = "mtcars Dataset",
    x = "Miles per Gallon", y = "Horsepower"
  ) +
  theme_kyle(base_size = 14)

ggplot(mtcars) +
  geom_point(aes(x = mpg, y = hp)) +
  facet_wrap(~cyl) +
  labs(
    title = "mtcars Dataset",
    x = "Miles per Gallon", y = "Horsepower"
  ) +
  theme_kyle(base_size = 14)

library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source 
#>   `/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/sf/shape/nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27

ggplot(nc) +
  geom_sf(aes(fill = BIR74)) +
  scale_fill_viridis_c() + 
  theme_kyle(base_size = 14) + 
  theme_map()

gt theme

This theme borrow heavily from Thomas Mock

library(gt)

mtcars[1:5, ] |>
  gt() |>
  gt_theme_kyle() |>
  tab_header(title = make_gt_title("mtcars Dataset")) |>
  tab_source_note(source_note = "Data from mtcars in R") |>
  as_raw_html()
mtcars Dataset
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Data from mtcars in R

About

https://kylebutts.github.io/kfbmisc/

License:Other


Languages

Language:R 68.3%Language:C++ 31.7%