--- title: "colormapパッケージ" output: flexdashboard::flex_dashboard: orientation: columns social: menu source_code: embed runtime: shiny --- ```{r global, include=FALSE} #必要パッケージの読み込み library("colormap") library("tidyverse") library("flexdashboard") library("DT") ###データ例の作成##### n <- 100 TestData <- data.frame("Group" = sample(paste0("Group", 1:5), n, replace = TRUE), "Data1" = sample(1:10, n, replace = TRUE), "Data2" = sample(LETTERS[1:24], n, replace = TRUE)) ######## #「colormap」パッケージ:カラーパレット名:44種類 GgSColName <- c("jet","hsv","hot","cool","spring","summer", "autumn","winter","bone","copper","greys", "YIGnBu","greens","YIOrRd","bluered","RdBu", "picnic","rainbow","portland","blackbody","earth", "electric","viridis","inferno","magma","plasma", "warm","cool","rainbow-soft","bathymetry","cdom", "chlorophyll","density","freesurface-blue","freesurface-red", "oxygen","par","phase","salinity","temperature","turbidity", "velocity-blue","velocity-green","cubehelix") ``` Column {data-width=500} ------------------------------------- ```{r} selectInput('Colpal', '収録カラーパレット:44種類', GgSColName) sliderInput('ColNo', 'カラーパレットの色数', value = 5, min = 5, max = 20) ``` ###カラーコード ```{r} renderDataTable({ ColCodeData <- data.frame("Color_Code" = as.character(colormap_pal(colormap = input$Colpal)(input$ColNo)), "Color" = "") datatable(ColCodeData, rownames = FALSE, options = list(pageLength = 10, lengthMenu = c(20, 40, 100))) %>% formatStyle("Color", valueColumns = "Color_Code", backgroundColor = styleEqual(ColCodeData[, 1], ColCodeData[, 1])) }) ``` Column {data-width=500} ------------------------------------- ###ggplot2:colorに適応 ```{r} renderPlot({ ggplot(TestData, aes(x = Data1, y = Data2, col = Group)) + geom_point(size = 10) + theme_bw() + scale_color_manual(values = colormap_pal(colormap = input$Colpal)(input$ColNo)) + labs(title = paste0("パレット名:", input$Colpal)) }) ``` ###ggplot2:fillに適応 ```{r} renderPlot({ ggplot(TestData, aes(x = Data2, fill = Group)) + geom_bar(stat = "count") + theme_bw() + scale_fill_manual(values = colormap_pal(colormap = input$Colpal)(input$ColNo)) + labs(title = paste0("パレット名:", input$Colpal)) }) ```