--- title: "gameRパッケージ" output: flexdashboard::flex_dashboard: orientation: columns social: menu source_code: embed runtime: shiny --- ```{r global, include=FALSE} #必要パッケージの読み込み library("gameR") library("tidyverse") library("flexdashboard") library("DT") ###データ例の作成##### n <- 100 TestData <- data.frame("Group" = sample(paste0("Group", 1:3), n, replace = TRUE), "Data1" = sample(1:10, n, replace = TRUE), "Data2" = sample(LETTERS[1:24], n, replace = TRUE)) ######## #「gameR_cols」パッケージ:カラーパレット名:9種類 GgSColName <- gameR_cols() ``` Column {data-width=500} ------------------------------------- ```{r} selectInput('Colpal', '収録カラーパレット:9種類', GgSColName) ``` ```{r} renderDataTable({ PalData <- eval(parse(text = paste0("gameR_cols('", input$Colpal, "')"))) ColCodeData <- data.frame("Color_Code" = PalData, "Color" = "") datatable(ColCodeData, rownames = FALSE, options = list(pageLength = 7, lengthMenu = c(5, 10, 20))) %>% formatStyle("Color_Code", textAlign = "center") %>% formatStyle("Color", valueColumns = "Color_Code", color = "white", fontWeight = "bold", textAlign = "center", backgroundColor = styleEqual(ColCodeData[, 1], ColCodeData[, 1])) }) ``` ###ggplot2:カラーパレット表示 ```{r} renderPlot({ PalCol <- tibble(ColCode = eval(parse(text = paste0("gameR_cols('", input$Colpal, "')")))) ggplot(PalCol, aes(x = ColCode, y = 1, fill = ColCode, label = ColCode)) + geom_raster() + annotate("rect", xmin = -Inf, xmax = Inf, ymin = 0.93, ymax = 1.07, alpha = 0.7, fill = "white") + geom_text(aes(label = input$Colpal, x = (nrow(PalCol)+1)/2, y = 1), color = "black", size = 8) + scale_fill_manual(values = as.character(PalCol$ColCode), guide = "none") + theme_void() }, height = 200) ``` Column {data-width=500} ------------------------------------- ###ggplot2:colorに適応 ```{r} renderPlot({ PalData <- eval(parse(text = paste0("gameR_cols('", input$Colpal, "')"))) ggplot(TestData, aes(x = Data1, y = Data2, col = Group)) + geom_point(size = 10) + theme_bw() + scale_color_manual(values = as.character(PalData)) + labs(title = paste0("Palette Name:", input$Colpal)) }, height = 350) ``` ###ggplot2:fillに適応 ```{r} renderPlot({ PalData <- eval(parse(text = paste0("gameR_cols('", input$Colpal, "')"))) ggplot(TestData, aes(x = Data2, fill = Group)) + geom_bar(stat = "count") + theme_bw() + scale_fill_manual(values = as.character(PalData)) + labs(title = paste0("Palette Name:", input$Colpal)) }, height = 350) ```