initialize and customize some charts

This commit is contained in:
Bombo 2023-04-03 14:12:13 +02:00
commit 5d44e8de2b
2 changed files with 46683 additions and 0 deletions

46524
data.csv Normal file

File diff suppressed because it is too large Load Diff

159
projekt.R Normal file
View File

@ -0,0 +1,159 @@
library(shiny) # Main library
library(ggplot2) # Plots
library(dplyr) # Data manipulate
library(shinythemes)
library(plotly)
CO_data <- read.csv("./data.csv", header= TRUE)
col_names = colnames(CO_data)
countries <- unique(CO_data['country'])
ui <- navbarPage(
titlePanel(title=div(img(src="https://siw.amu.edu.pl/__data/assets/file/0004/162751/logo_wersja-podstawowa_granat_1.jpg", width = 50, height = 50), 'explore CO2 data')),
tabPanel("Linear Chart",
sidebarLayout(
sidebarPanel(
selectInput('country',
'Select Country',
selected = 'Afghanistan',
choices = countries
),
selectInput('category',
'Select Category',
selected = 'population',
choices = col_names
)
),
mainPanel(
plotlyOutput('linear_chart')
),
)
),
tabPanel(
'GDP',
plotlyOutput('gdp')
),
tabPanel(
'TOP Production',
fluidRow(
column(6,plotlyOutput(outputId="the_most_1")),
column(6,plotlyOutput(outputId="the_most_2")),
column(6,plotlyOutput(outputId="the_most_3"))
)
),
tabPanel(
'Smallest production',
fluidRow(
column(6,plotlyOutput(outputId="the_least_1")),
column(6,plotlyOutput(outputId="the_least_2")),
column(6,plotlyOutput(outputId="the_least_3"))
)
),
tabPanel(
'Data',
DT::dataTableOutput('tableData')
),
tabPanel(
'Theme',
shinythemes::themeSelector(),
theme = shinythemes::shinytheme('flatly'),
)
)
server <- function(input, output, session) {
output$tableData <- DT::renderDataTable({
CO_data %>%
filter(country == input$country) %>%
DT::datatable()
})
output$linear_chart <- renderPlotly({
CO_data %>%
filter(country == input$country) %>%
ggplot(aes(x = year, y = get(input$category))) +
geom_line()
})
output$gdp <- renderPlotly({
CO_data %>%
filter(year == 2011) %>%
ggplot(aes(x = gdp, y = co2, label = country)) +
geom_line() +
geom_point() +
ggtitle('Placement of countries by CO2 and GDP production')
})
output$the_most_1 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_max(n=7, order_by = co2_per_gdp) %>%
ggplot(aes(x=country, y=co2_per_gdp, fill=country)) +
xlab('Country') +
ylab('CO2 per GDP') +
ggtitle('The TOP production per GDP') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
output$the_most_2 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_max(n=7, order_by = co2_per_capita) %>%
ggplot(aes(x=country, y=co2_per_capita, fill=country), custom) +
xlab('Country') +
ylab('CO2 per capita') +
ggtitle('The TOP production per capita') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
output$the_most_3 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_max(n=7, order_by = co2_per_capita) %>%
ggplot(aes(x=country, y=co2_per_capita, fill=country)) +
xlab('Country') +
ylab('CO2 overall') +
ggtitle('The TOP production overall') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
output$the_least_1 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_min(n=7, order_by = co2_per_gdp) %>%
ggplot(aes(x=country, y=co2_per_gdp, fill=country)) +
xlab('Country') +
ylab('CO2 per GDP') +
ggtitle('The smalest production per GDP') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
output$the_least_2 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_min(n=7, order_by = co2_per_capita) %>%
ggplot(aes(x=country, y=co2_per_capita, fill=country)) +
xlab('Country') +
ylab('CO2 per capita') +
ggtitle('The smalest production per capita') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
output$the_least_3 = renderPlotly({
CO_data %>%
filter(year==2011) %>%
slice_min(n=7, order_by = co2) %>%
ggplot(aes(x=country, y=co2, fill=country)) +
xlab('Country') +
ylab('CO2 overall') +
ggtitle('The smalest production overall') +
theme(axis.text.x = element_blank()) +
geom_bar(stat='identity')
})
}
shinyApp(ui = ui, server = server)