Final changes

This commit is contained in:
lewy 2023-06-14 10:58:06 +02:00
parent 278b1622ea
commit c3d100ece3
3 changed files with 48 additions and 41 deletions

View File

@ -2,9 +2,8 @@ library(dplyr)
# install.packages("ggplot2") # install.packages("ggplot2")
library(ggplot2) library(ggplot2)
library(plotly) library(plotly)
countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO', 'XD') countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO')
countries = unique(SHP_28$geo)
countries <- unique(map_df$geo)
df = read.csv(".//data//prc_hicp_aind_page_linear.csv") df = read.csv(".//data//prc_hicp_aind_page_linear.csv")
df[,c("geo", "TIME_PERIOD", "OBS_VALUE")] df[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
@ -51,7 +50,7 @@ ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label
plot <- ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>", plot <- ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>",
"Rok: ", TIME_PERIOD, "<br>", "Rok: ", TIME_PERIOD, "<br>",
"Warto?? wska?nika: ", OBS_VALUE))) + "Wartoœæ wskaŸnika: ", OBS_VALUE))) +
geom_line(aes(group = geo)) + geom_line(aes(group = geo)) +
geom_point() + geom_point() +
labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') + labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') +
@ -86,15 +85,15 @@ ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label
slice(n() - 1), slice(n() - 1),
aes(label = geo, hjust = -1, size = 4))+ aes(label = geo, hjust = -1, size = 4))+
scale_x_continuous(breaks=seq(2010,2024,2)) scale_x_continuous(breaks=seq(2010,2024,2))
labs(x = "Rok", y = 'Indeks Cen nieruchomo?ci [cena z 2015 roku = 100]') labs(x = "Rok", y = 'Indeks Cen nieruchomoœci [cena z 2015 roku = 100]')
plot <- ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>", plot <- ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>",
"Rok: ", TIME_PERIOD, "<br>", "Rok: ", TIME_PERIOD, "<br>",
"Warto?? wska?nika: ", OBS_VALUE))) + "Wartoœæ wskaŸnika: ", OBS_VALUE))) +
geom_line() + geom_line() +
geom_point() + geom_point() +
scale_x_continuous(breaks = seq(2010, 2024, 2)) + scale_x_continuous(breaks = seq(2010, 2024, 2)) +
labs(x = "Rok", y = 'Indeks Cen nieruchomo?ci [cena z 2015 roku = 100]') labs(x = "Rok", y = 'Indeks Cen nieruchomoœci [cena z 2015 roku = 100]')
plotly_plot <- ggplotly(plot, tooltip = "text") plotly_plot <- ggplotly(plot, tooltip = "text")
for (i in 1:length(plotly_plot$x$data)) { for (i in 1:length(plotly_plot$x$data)) {
if (plotly_plot$x$data[[i]]$type == "scatter") { if (plotly_plot$x$data[[i]]$type == "scatter") {
@ -133,7 +132,7 @@ ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)
plot <- ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>", plot <- ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>",
"Rok: ", TIME_PERIOD, "<br>", "Rok: ", TIME_PERIOD, "<br>",
"Warto?? wska?nika: ", OBS_VALUE))) + "Wartoœæ wskaŸnika: ", OBS_VALUE))) +
geom_line() + geom_line() +
geom_point() + geom_point() +
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') + labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
@ -174,12 +173,8 @@ merged_df %>% group_by(geo) %>% str()
str(merged_df) str(merged_df)
unfiltered_df <- merged_df
merged_df <- filter(merged_df, geo %in% countries) merged_df <- filter(merged_df, geo %in% countries)
ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) + ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
geom_line(linetype="dotted", size=1) + geom_line(linetype="dotted", size=1) +
geom_point(aes(x=TIME_PERIOD, y=house_prices_wo_hicp)) + geom_point(aes(x=TIME_PERIOD, y=house_prices_wo_hicp)) +
@ -190,12 +185,12 @@ ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
stat_function(fun=function(x) 100*(1.04)^(x-2015), aes(colour = "4% Compounding")) + stat_function(fun=function(x) 100*(1.04)^(x-2015), aes(colour = "4% Compounding")) +
stat_function(fun=function(x) 100*(1.07)^(x-2015), aes(colour = "7% Compounding")) + stat_function(fun=function(x) 100*(1.07)^(x-2015), aes(colour = "7% Compounding")) +
scale_x_continuous(breaks=seq(2010,2024,2)) + scale_x_continuous(breaks=seq(2010,2024,2)) +
labs(x = "Year", y = 'Indeks cen nieruchomo?ci zdyskontowany o warto?? inflacji [2015 = 100]') labs(x = "Year", y = 'Indeks cen nieruchomoœci zdyskontowany o wartoœæ inflacji [2015 = 100]')
final_plot <- ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo, final_plot <- ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo,
text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>", text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>",
"Cena nieruchomo?ci: ", house_prices_wo_hicp))) + "Cena nieruchomoœci: ", house_prices_wo_hicp))) +
geom_line(aes(group = geo), linetype = "dotted", size = 1) + geom_line(aes(group = geo), linetype = "dotted", size = 1) +
geom_point() + geom_point() +
geom_text(data = merged_df %>% group_by(geo) %>% slice(n()), geom_text(data = merged_df %>% group_by(geo) %>% slice(n()),
@ -203,7 +198,7 @@ final_plot <- ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, c
stat_function(fun = function(x) 100*(1.04)^(x-2015), aes(colour = "4% Compounding"), inherit.aes = FALSE) + stat_function(fun = function(x) 100*(1.04)^(x-2015), aes(colour = "4% Compounding"), inherit.aes = FALSE) +
stat_function(fun = function(x) 100*(1.07)^(x-2015), aes(colour = "7% Compounding"), inherit.aes = FALSE) + stat_function(fun = function(x) 100*(1.07)^(x-2015), aes(colour = "7% Compounding"), inherit.aes = FALSE) +
scale_x_continuous(breaks = seq(2010, 2024, 2)) + scale_x_continuous(breaks = seq(2010, 2024, 2)) +
labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]") labs(x = "Rok", y = "Indeks cen nieruchomoœci zdyskontowany o wartoœæ inflacji [2015 = 100]")
final_plot final_plot

View File

@ -40,6 +40,8 @@ SHP_28 %>%
# Join datasets # Join datasets
mapdata_new <- left_join(SHP_28, map_df, by="geo", relationship = "many-to-many") mapdata_new <- left_join(SHP_28, map_df, by="geo", relationship = "many-to-many")
merged_df <- left_join(SHP_28, merged_df, by="geo", relationship = "many-to-many")
merged_df
# Delete Greece (null values) # Delete Greece (null values)
mapdata_new <- mapdata_new[-9,] mapdata_new <- mapdata_new[-9,]

View File

@ -12,13 +12,19 @@ ui <- fluidPage(
sliderInput("range", "Compound interest:",min = 0, max = 10, value = c(4,8)),textOutput("Compound interest slider"), sliderInput("range", "Compound interest:",min = 0, max = 10, value = c(4,8)),textOutput("Compound interest slider"),
# Checkboxes # Checkboxes
# tags$head(tags$style(HTML(".checkbox {margin-left:15px}"))),
checkboxGroupInput("countries", "Chosen countries:", checkboxGroupInput("countries", "Chosen countries:",
choiceNames = unique(map_df$geo), choiceNames = map_df$region,
choiceValues = unique(map_df$geo), choiceValues = map_df$geo,
selected = c("PL", "DE", "CZ") selected = c("PL", "DE", "CZ"),
inline = TRUE,
width = "75%"
), ),
width=3 width=3
), ),
@ -26,7 +32,7 @@ ui <- fluidPage(
h1("Real house prices index"), h1("Real house prices index"),
tabsetPanel( tabsetPanel(
tabPanel("Plot", plotOutput("final_plot")), tabPanel("Plot", plotlyOutput("final_plot")),
tabPanel("Map", leafletOutput("mymap")), tabPanel("Map", leafletOutput("mymap")),
tabPanel("Table", dataTableOutput('table')) tabPanel("Table", dataTableOutput('table'))
), ),
@ -44,37 +50,41 @@ ui <- fluidPage(
# Backend # Backend
server <- function(input, output, session) { server <- function(input, output, session) {
# Używanie wektora indeksu do indeksowania innych danych output$table <- renderDataTable({
output$table <- renderDataTable(merged_df[,!names(merged_df) %in% c("OBS_VALUE.x", "OBS_VALUE.y")]) merged_df[, !names(merged_df) %in% c("OBS_VALUE.x", "OBS_VALUE.y", "geometry")]
}, options = list(pageLength = 10))
# Plot module # Plot module
output$final_plot <- renderPlot({ output$final_plot <- renderPlotly({
final_plot <- ggplot(filter(merged_df, geo %in% input$countries),
# final_plot <- aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo,
ggplot(filter(merged_df, geo %in% input$countries), aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo, text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>",
text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>", "Cena nieruchomości: ", house_prices_wo_hicp))) +
"Cena nieruchomości: ", house_prices_wo_hicp))) +
geom_line(aes(group = geo), linetype = "dotted", size = 1) + geom_line(aes(group = geo), linetype = "dotted", size = 1) +
geom_point() + geom_point() +
geom_text(data = merged_df %>% group_by(geo) %>% slice(n()), geom_text(data = filter(merged_df, geo %in% input$countries) %>% group_by(geo) %>% slice(n()),
aes(label = "", hjust = -0.2, size = 4)) + aes(label = "", hjust = -0.2, size = 4)) +
stat_function(fun = function(x) 100*(1+input$range[1]/100)^(x-2015), aes(colour = "4% Compounding"), inherit.aes = FALSE) + stat_function(fun = function(x) 100*(1+input$range[1]/100)^(x-2015), aes(colour = paste0(as.character(input$range[1]), "% Compounding")), inherit.aes = FALSE) +
stat_function(fun = function(x) 100*(1+input$range[2]/100)^(x-2015), aes(colour = "7% Compounding"), inherit.aes = FALSE) + stat_function(fun = function(x) 100*(1+input$range[2]/100)^(x-2015), aes(colour = paste0(as.character(input$range[2]), "% Compounding")), inherit.aes = FALSE) +
scale_x_continuous(breaks = seq(2010, 2024, 2)) + scale_x_continuous(breaks = seq(2010, 2024, 2)) +
# labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]") + labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]",
theme( axis.title = element_blank() ) color = "Countries") +
theme(axis.title = element_blank())
# ggplotly(final_plot, tooltip = "text") plotly_plot <- ggplotly(final_plot, tooltip = "text")
for (i in 1:length(plotly_plot$x$data)) {
if (plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding") || plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding")) {
plotly_plot$x$data[[i]]$hoverinfo <- "name+y"
}
}
plotly_plot %>% layout(showlegend = TRUE, legend = list(title = list(text = "Countries")))
})
#for (i in 1:length(plotly_plot$x$data)) {
# if (plotly_plot$x$data[[i]]$name == "4% Compounding" || plotly_plot$x$data[[i]]$name == "7% Compounding") {
# plotly_plot$x$data[[i]]$hoverinfo <- "name+y"
# }
#}
#plotly_plot
})
# Map module # Map module