Last active
February 18, 2016 02:47
-
-
Save heavywatal/02624db549d2dd9a7594 to your computer and use it in GitHub Desktop.
List colors with ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
library(stringr) | |
library(pipeR) | |
.data = data_frame(fill=colours()) %>>% | |
mutate(basename=str_extract(fill, '[^\\d]+'), number=extract_numeric(fill)) %>>% | |
dplyr::filter(!(basename %in% c('gray', 'grey') & (number %% 10 != 0))) %>>% | |
replace_na(list(number=0)) %>>% | |
arrange(basename, number) %>>% | |
mutate(colour=ifelse(colMeans(col2rgb(fill)) < 128, 'white', 'black'), | |
fill=factor(fill, levels=fill)) %>>% | |
(?.) | |
gp = ggplot(.data, aes(x=0, y=0, fill=fill))+ | |
geom_raster()+ | |
geom_text(aes(label=fill, colour=colour), family='mono')+ | |
scale_fill_identity()+ | |
scale_colour_identity()+ | |
facet_wrap(~fill, ncol=53, dir='v')+ | |
theme_void()+ | |
theme(legend.position='none')+ | |
theme(panel.margin=grid::unit(0, 'mm')) | |
dev.off() | |
quartz(width=16, height=12) | |
gp | |
ggsave('R_colors.pdf', gp, width=16, height=12) | |
quartz.save('R_colors_quartz.pdf', type='pdf') | |
quartz.save('R_colors.png') |
Author
heavywatal
commented
Feb 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment