ggextra package-ggmarginal and example -shiny and shinyjs

12
Prepared by Volkan OBAN Reference: https://github.com/daattali/ggExtra GGEXTRA Package in R: GGEXTRA- ggMarginal: install.packages("ggExtra") or devtools::install_github("daattali/ggExtra") suppressPackageStartupMessages({ library("ggExtra") library("ggplot2") })

Upload: volkan-oban

Post on 12-Apr-2017

55 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Page 1: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

Prepared by Volkan OBANReference: https://github.com/daattali/ggExtra

GGEXTRA Package in R:

GGEXTRA- ggMarginal:

install.packages("ggExtra")

or

devtools::install_github("daattali/ggExtra")

suppressPackageStartupMessages({ library("ggExtra") library("ggplot2")})

Page 2: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs
Page 3: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

Codes:

> library(ggplot2)> library(ggExtra)> data(mtcars)> p <- ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point()> ggMarginal(p)> set.seed(30)> df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))> p2 <- ggplot2::ggplot(df, ggplot2::aes(x, y)) + ggplot2::geom_point()> ggMarginal(p2)> ggMarginal(p2, type = "histogram"

Page 4: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

Codes:

> set.seed(30)> df1 <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))> (p1 <- ggplot(df1, aes(x, y)) + geom_point() + theme_bw())> ggMarginal(p1, margins = "x", size = 2, type = "histogram",+ col = "blue", fill = "orange")

Page 5: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

cod

Code:ggMarginal(p1, type = "histogram", xparams = list(binwidth = 1, fill = "orange"))

Reference: https://github.com/daattali/ggExtra

Page 6: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

SHINY AND SHINYJS

Reference: https://github.com/daattali/shinyjs

shinyjs - Easily improve the user interaction and user experience in your Shiny apps in seconds

install.packages("shinyjs")

or

devtools::install_github("daattali/shinyjs")

Example:

library(shiny)> library(shinyjs)> > jsCode <- "shinyjs.pageCol = function(params){$('body').css('background', params);}"> > shinyApp(+ ui = fluidPage(+ useShinyjs(),+ extendShinyjs(text = jsCode),+ selectInput("col", "Colour:",+ c("white", "yellow", "red", "blue", "purple"))+ ),+ server = function(input, output) {+ observeEvent(input$col, {+ js$pageCol(input$col)+ })+ }+ )

Page 7: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs
Page 8: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs
Page 9: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs

Example 2:> library(shiny)> shinyApp(+ ui = fluidPage(+ shinyjs::useShinyjs(),+ shinyjs::inlineCSS(list(.big = "font-size: 2em")),+ div(id = "myapp",+ h2("shinyjs demo"),+ checkboxInput("big", "Bigger text", FALSE),+ textInput("name", "Name", ""),+ a(id = "toggleAdvanced", "Show/hide advanced info", href = "#"),+ shinyjs::hidden(+ div(id = "advanced",+ numericInput("age", "Age", 30),+ textInput("company", "Company", "")+ )+ ),+ p("Timestamp: ",+ span(id = "time", date()),+ a(id = "update", "Update", href = "#")+ ),+ actionButton("submit", "Submit"),+ actionButton("reset", "Reset form")+ )+ ),+ + server = function(input, output) {+ observe({+ shinyjs::toggleState("submit", !is.null(input$name) && input$name != "")+ })+ + shinyjs::onclick("toggleAdvanced",+ shinyjs::toggle(id = "advanced", anim = TRUE)) + + shinyjs::onclick("update", shinyjs::html("time", date()))+ + observe({+ shinyjs::toggleClass("myapp", "big", input$big)+ })+ + observeEvent(input$submit, {+ shinyjs::info("Thank you!")+ })+ + observeEvent(input$reset, {+ shinyjs::reset("myapp")+ }) + }+ )

Page 10: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs
Page 11: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs
Page 12: ggExtra Package-ggMarginal and Example -Shiny and Shinyjs