Package

ggkeyboard

Author

Sharla Gelfand

The ggkeyboard package is not on CRAN. Use the install_github function from devtools to install it.

# install.packages("devtools")
devtools::install_github("sharlagelfand/ggkeyboard", ref = "main")

Basic keyboard

The basic keyboard can be created making use of the ggkeyboard function. The function will create a default keyboard if no arguments are specified.

library(ggkeyboard)

ggkeyboard()

Draw a basic keyboard in R ggplot2

The font size of the keys can be resized with the font_size argument. Default value is 3. You can also change the font family with font_family.

library(ggkeyboard)

ggkeyboard(font_size = 2,
           font_family = "Arial")

Change the keyboard size and font family

Thre are two layouts available. Default value is layout = "ansi" but you can also use "iso".

library(ggkeyboard)

ggkeyboard(layout = "iso")

Keyboard layout

Keyboard color palettes

You can choose between different pre-built color palettes, such as "pastel" (default), "serika", "wahtsy", "cyberpunk", "magic", "varmilo" and "t0mb3ry". You can also specify custom colors.

Serika palette

serika

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("serika"))

Wahtsy palette

wahtsy

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("wahtsy"))

Cyberpunk palette

cyberpunk

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("cyberpunk"))

Magic palette

magic

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("magic"))

Varmilo palette

varmilo

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("varmilo"))

T0mb3ry palette

t0mb3ry

library(ggkeyboard)

ggkeyboard(palette = keyboard_palette("t0mb3ry""))

Types of keyboards

There are several types of keyboards you can set, such as full, sixty-percent, and mac. Each of them comes with a color palette.

Full (with numeric keyboard)

library(ggkeyboard)

ggkeyboard(full,
           palette = keyboard_palette("varmilo"),
           font_size = 2.75)

Full keyboard in ggplot2

Sixty percent (sixty percent layout)

library(ggkeyboard)

ggkeyboard(sixty_percent,
           palette = keyboard_palette("t0mb3ry"),
           adjust_text_colour = FALSE)

Sixty percent keyboard in R ggplot2

Mac (based on the Apple magic keyboard)

library(ggkeyboard)

ggkeyboard(mac,
           palette = keyboard_palette("magic"))

Mac keyboard in ggplot2

Key highlighting

It is possible to highlight the some keys of the keyboard with the highlight_keys function.

Highlight keyboard keys

You can add a border around the selected keys as follows:

library(ggkeyboard)

ggkeyboard() %>%
  highlight_keys(c("A", "W", "S", "D"), colour = "red")

Highlighting ggplot2 keyboard keys

You can also add a fill color to the keys with the fill argument. A good option is to use the rgb function to add a color with transparency.

library(ggkeyboard)

ggkeyboard() %>%
  highlight_keys(c("A", "W", "S", "D"),
                 colour = "red",
                 fill = rgb(1, 0, 0, alpha = 0.25))

See also