Óscar Prieto
15/11/20
This app was designed with the purpose of making exploratory analysis on the mtcars dataset easy and accesible for every person, even those who are not in touch with coding in R. The dataset we used is a mere example; the true objective would be the application of this general process to any dataset to make it more approachable.
The following car features are used:
It allows us to plot different features of the dataset in the axis
It is possible to apply a smoother
It can facet rows and columns
library(shiny)
library(ggplot2)
dataset <- mtcars
shinyUI(pageWithSidebar(
headerPanel("mtcars dataset plotter"),
sidebarPanel(
sliderInput('sampleSize', 'Sample Size', min=10, max=nrow(dataset),
value=min(10, nrow(dataset)), step=5, round=0),
selectInput('x', 'X', names(dataset)),
selectInput('y', 'Y', names(dataset), names(dataset)[[2]]),
selectInput('color', 'Color', c('None', names(dataset))),
checkboxInput('smooth', 'Smooth'),
selectInput('facet_row', 'Facet Row', c(None='.', names(dataset))),
selectInput('facet_col', 'Facet Column', c(None='.', names(dataset)))
),
mainPanel(
plotOutput('plot')
)
))
<!–html_preserve–>
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
dataset <- reactive( {
mtcars[sample(nrow(mtcars), input$sampleSize),]
})
output$plot <- reactivePlot(function() {
p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .')
p <- p + facet_grid(facets)
if (input$smooth)
p <- p + geom_smooth()
print(p)
}, height=600
)
})