Ivan Ip
19th February 2019
Dataset “diamonds” is sourced from R package ggplot. This presentation is to summarize the Criteria Count,
Criteria of Diamonds,
In addition, Violin Plot shows their dispersion with Carat.
library(ggplot2)
data("diamonds")
summary(diamonds[,1:4])
carat cut color clarity
Min. :0.2000 Fair : 1610 D: 6775 SI1 :13065
1st Qu.:0.4000 Good : 4906 E: 9797 VS2 :12258
Median :0.7000 Very Good:12082 F: 9542 SI2 : 9194
Mean :0.7979 Premium :13791 G:11292 VS1 : 8171
3rd Qu.:1.0400 Ideal :21551 H: 8304 VVS2 : 5066
Max. :5.0100 I: 5422 VVS1 : 3655
J: 2808 (Other): 2531
library(shiny)
library(ggplot2)
library(data.table)
data("diamonds")
Diamond_CC = data.table(diamonds)
Diamond_ui = fluidPage(
titlePanel("Diamond Carat Summary"),
sidebarLayout(
sidebarPanel(
selectInput("Criteria", "Choose a Criteria (x = ):",
choices = c("Cut", "Color", "Clarity")),
h5("y = Carat"),
br(),
actionButton("update", "Update View")
),
mainPanel(
h4("Summary by Criteria Count"),
verbatimTextOutput("summary"),
h4("Violin Plot by Criteria"),
plotOutput("plot")
)
)
)
Diamonds_server = shinyServer(function(input, output){
data = eventReactive(input$update, {
switch(input$Criteria,
"Cut" = Diamond_CC$cut, "Color" = Diamond_CC$color,
"Clarity" = Diamond_CC$clarity)
})
output$summary = renderPrint({
summary(data())
})
output$plot = renderPlot({
ggplot(Diamond_CC, aes_string(x = data(), y = Diamond_CC$carat)) + geom_violin()
})
})
shinyApp(Diamond_ui, Diamonds_server)
Thank you