Skip to contents

Display a grid of color swatches with optional names or color codes.

Usage

visual_colors(
  colors,
  names = NULL,
  num_per_row = 30,
  title = NULL,
  rgb = NULL,
  hex = NULL
)

Arguments

colors

A character vector of color codes (hex format, e.g., "#FF0000").

names

Optional. A character vector of names for each color. Default is NULL, which means color codes will be displayed.

num_per_row

Number of colors per row. Default is 30.

title

Optional title for the visualization. Default is NULL.

rgb

Optional. A character vector of RGB values (e.g., "(255, 0, 0)"). If provided and names is NULL, RGB values will be displayed as names.

hex

Optional. A logical or character vector. If TRUE and names is NULL, hex codes will be displayed as names. If a character vector is provided, it will be used as names.

Value

An HTML widget that can be displayed with htmltools::browsable.

Examples

# Visualize a simple color palette
colors <- c("#FF0000", "#00FF00", "#0000FF")
widget <- visual_colors(colors, names = c("Red", "Green", "Blue"))
htmltools::browsable(widget)
Red
Green
Blue
# Visualize a built-in palette widget2 <- visual_colors(thisplot::palette_list$Paired) htmltools::browsable(widget2)
#A6CEE3
#1F78B4
#B2DF8A
#33A02C
#FDBF6F
#FF7F00
#FB9A99
#E31A1C
#CAB2D6
#6A3D9A
#FFFF99
#B15928
# Use with ChineseColors cc <- ChineseColors() widget3 <- visual_colors( colors = cc$blue[1:60], title = "Chinese Blue Colors" ) htmltools::browsable(widget3)
Chinese Blue Colors
#0F1423
#131824
#101F30
#142334
#12264F
#1C2938
#132C33
#1A2847
#003460
#19325F
#21373D
#003371
#213A70
#003D74
#38308E
#1C3F73
#22406A
#06436F
#134857
#144A74
#454659
#45465E
#354E6B
#12507B
#2E4E7E
#26499D
#004EA2
#535164
#2A5390
#424D99
#15559A
#0F59A4
#1661AB
#11659A
#106898
#126E82
#4B5CC4
#126BAE
#4F64AE
#346C9C
#3170A7
#1772B4
#3271AE
#2B73AF
#2474B5
#1177B0
#1677B3
#2376B7
#2177B8
#5E7987
#4E7CA1
#5976BA
#6B798E
#1781B5
#4182A4
#2983BB
#2486B9
#158BB8
#2F90B9
#1A94BC