Interactive Visualization in R
Interactive Visualization in R
Visualization in R
Interactive Visualization
library(ggplot2)
data(iris)
ggplot(data = iris) +
geom_point(mapping =
aes(x = Sepal.Width, y =
Petal.Width, color =
Species))
The plotly package
Syntax:
library(shiny)
ui <- fluidPage()
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
library(shiny)
library(plotly) # Define server logic
# Define UI server <- function(input, output) {
ui <- fluidPage( output$plot <- renderPlotly({
titlePanel("Interactive Plot with mtcars # Create plotly plot based on user
Dataset"), inputs
sidebarLayout( plot_ly(data = mtcars, x =
sidebarPanel( ~get(input$x_var), y =
selectInput("x_var", "X-axis ~get(input$y_var),
variable:", choices = names(mtcars)),
type = 'scatter', mode =
selectInput("y_var", "Y-axis
variable:", choices = names(mtcars), 'markers') %>%
selected = "mpg") layout(title = 'Interactive Plot with
), mtcars Dataset',
mainPanel( xaxis = list(title = input$x_var),
plotlyOutput("plot") yaxis = list(title = input$y_var))
) })
) }
)
# Run the application
shinyApp(ui = ui, server = server)