ggextra package-ggmarginal and example -shiny and shinyjs
Post on 12-Apr-2017
56 Views
Preview:
TRANSCRIPT
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")})
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"
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")
cod
Code:ggMarginal(p1, type = "histogram", xparams = list(binwidth = 1, fill = "orange"))
Reference: https://github.com/daattali/ggExtra
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)+ })+ }+ )
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")+ }) + }+ )
top related