R offers a wealth of built-in colors, with more than 650 options readily available to use in your visualizations. These colors can be accessed by name rather than relying on hex codes or RGB values, making it easier to enhance the aesthetics of your charts and graphs. While the colors()
function provides a list of all available color names, it doesn’t display what these colors actually look like. To make choosing colors easier, there are online tools and PDFs available, but for those who prefer to work directly in R, creating a custom searchable table of colors can be an efficient solution.
To help with this, a package called rcolorutils
has been developed to display a sortable and searchable table of R’s built-in colors. After installing the package from GitHub, you can easily generate a table that not only lists the color names but also allows you to search by RGB values. This feature is particularly useful since many color names may not directly describe their color (e.g., variations of “blue” may not contain the word “blue” in their names). The table also allows sorting by different columns and even filtering with regular expressions, such as searching for all shades of “gray” by using patterns like “gr.y.”
Another helpful feature of this tool is the ability to sort colors more logically, for instance, by their RGB values rather than just alphabetically. This provides a more intuitive way to find colors based on their characteristics, such as hue, saturation, or brightness. For those who need a more advanced search, the table can handle multi-column sorting, enabling more detailed exploration of colors. This approach eliminates the need for memorizing hex codes or relying on external tools to view the colors and their variations.
For users who prefer not to use a table, R also provides a way to search for colors that are similar to a specific reference color. Running the base R color demo (demo(colors)
) locally allows you to see how R categorizes colors and get an interactive experience of exploring these options. By experimenting with these features in R, you can easily find and apply the perfect color for any visualization or data project, ensuring that your charts are both visually appealing and informative.