--- title: "MetBrewerパッケージ" output: flexdashboard::flex_dashboard: orientation: columns social: menu source_code: embed runtime: shiny --- ```{r global, include=FALSE} #必要パッケージの読み込み library("MetBrewer") 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)) ######## #「MetBrewer」パッケージ:カラーパレット名:50種類 GgSColName <- c("Austria", "Cassatt1", "Cassatt2", "Cross", "Degas", "Derain", "Egypt", "Gauguin", "Greek", "Hiroshige", "Hokusai1", "Hokusai2", "Hokusai3", "Homer1", "Homer2", "Ingres", "Isfahan1", "Isfahan2", "Juarez", "Klimt", "Lakota", "Manet", "Monet", "Moreau", "Morgenstern", "Nattier", "Navajo", "NewKingdom", "Nizami", "OKeeffe1", "OKeeffe2", "Peru1", "Peru2", "Pillement", "Pissaro", "Redon", "Renoir", "Robert", "Signac", "Stevens", "Tara", "Thomas", "Tiepolo", "Troy", "Tsimshian", "VanGogh1", "VanGogh2", "VanGogh3", "Veronese", "Wissing") ``` Column {data-width=500} ------------------------------------- ```{r} selectInput('Colpal', 'Select Color Palette Name', GgSColName) ``` ###収録カラーパレット:50種類 ```{r} renderDataTable({ ColCodeData <- data.frame("Color_Code" = as.character(met.brewer(input$Colpal)), "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 = met.brewer(input$Colpal)) + labs(title = paste0("パレット名:", input$Colpal)) + theme_bw(base_family = "Yu Gothic") }) ``` ###ggplot2:fillに適応 ```{r} renderPlot({ ggplot(TestData, aes(x = Data2, fill = Group)) + geom_bar(stat = "count") + theme_bw() + scale_fill_manual(values = met.brewer(input$Colpal)) + labs(title = paste0("パレット名:", input$Colpal)) + theme_bw(base_family = "Yu Gothic") }) ```