0% found this document useful (0 votes)
7 views

Tugas 3 MSIM43101

Uploaded by

willian lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Tugas 3 MSIM43101

Uploaded by

willian lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Nama : WILLIAN

NIM : 043680846
UPBJJ : Batam

Tugas 3 MSIM4310
# Load necessary libraries
library(shiny)
library(ggplot2)
library(readxl)

# Create a data frame with the provided data


data <- data.frame(
Month = c("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober",
"November", "Desember"),
Temperature_Min = c(23.9, 24.2, 24.6, 24.5, 23.5, 22.8, 22.4, 24.0, 22.2, 23.2, 23.4, 23.6),
Temperature_Max = c(31.7, 32.0, 32.6, 33.1, 34.8, 34.0, 33.9, 35.2, 35.2, 36.0, 35.0, 35.6),
Temperature_Avg = c(26.9, 27.0, 27.5, 27.0, 27.8, 27.5, 27.5, 28.0, 28.5, 28.9, 28.4, 28.6),
Relative_Humidity = c(83, 83, 81, 81, 84, 83, 80, 76, 75, 74, 80, 78),
Atmospheric_Pressure = c(1012.8, 1013.1, 1013.4, 1012.2, 1012.0, 1012.4, 1013.1, 1013.1, 1013.4, 1013.8, 1012.0,
1012.7),
Wind_Velocity = c(2, 2, 3, 4, 3, 4, 4, 5, 5, 5, 4, 5),
Rainfall = c(344.8, 193, 197.8, 343.7, 213.5, 259.2, 162.7, 57.6, 0, 73.2, 60.9, 191.4),
Sunshine_Duration = c(31, 38, 53, 50, 47, 36, 52, 61, 36, 51, 49, 58)
)

# Define the UI
ui <- fluidPage(
titlePanel("Visualisasi Data Meteorologi Samarinda"),
sidebarLayout(
sidebarPanel(
selectInput("variable", "Pilih Variabel:",
choices = c("Suhu Udara (Min)" = "Temperature_Min",
"Suhu Udara (Max)" = "Temperature_Max",
"Suhu Udara (Rata-rata)" = "Temperature_Avg",
"Kelembaban" = "Relative_Humidity",
"Tekanan Udara" = "Atmospheric_Pressure",
"Kecepatan Angin" = "Wind_Velocity",
"Curah Hujan" = "Rainfall",
"Penyinaran Matahari" = "Sunshine_Duration")),
selectInput("plotType", "Pilih Jenis Plot:",
choices = c("Scatter Plot" = "scatter",
"Line Plot" = "line",
"Bar Plot" = "bar"))
),
mainPanel(
plotOutput("dataPlot"),
tableOutput("dataTable")
)
)
)

# Define the server logic


server <- function(input, output) {
output$dataPlot <- renderPlot({
gg <- ggplot(data, aes_string(x = "Month", y = input$variable)) +
labs(x = "Bulan", y = input$variable)

if (input$plotType == "scatter") {
gg <- gg + geom_point()
} else if (input$plotType == "line") {
gg <- gg + geom_line()
} else if (input$plotType == "bar") {
gg <- gg + geom_bar(stat = "identity")
}

gg
})

output$dataTable <- renderTable({


data
})
}

# Run the application


shinyApp(ui = ui, server = server)

You might also like