Changes
This commit is contained in:
parent
0d28556d38
commit
278b1622ea
@ -1,4 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
|
||||
library(dplyr)
|
||||
# install.packages("lifecycle")
|
||||
library(ggplot2)
|
||||
@ -143,147 +143,145 @@ ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
|
||||
labs(x = "Year", y = 'Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]')
|
||||
|
||||
=======
|
||||
library(dplyr)
|
||||
# install.packages("ggplot2")
|
||||
library(ggplot2)
|
||||
countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO')
|
||||
|
||||
df = read.csv(".//data//prc_hicp_aind_page_linear.csv")
|
||||
df[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
|
||||
df1 = read.csv(".//data//prc_hpi_a__custom_3617733_page_linear.csv")
|
||||
df1[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df1)
|
||||
|
||||
|
||||
df2 = read.csv(".//data//sdg_08_10_page_linear.csv")
|
||||
df2[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df2)
|
||||
|
||||
df3 = read.csv(".//data//tec00114_page_linear.csv")
|
||||
df3[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df3)
|
||||
print(df3)
|
||||
|
||||
# ##################################################
|
||||
# Single Country GDP graph
|
||||
|
||||
year_country_gdp <- df3 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
year_country_gdp <- na.omit(year_country_gdp)
|
||||
|
||||
colnames(year_country_gdp)
|
||||
|
||||
df3 %>% group_by(geo) %>% str()
|
||||
|
||||
str(year_country_gdp)
|
||||
|
||||
year_country_gdp <- filter(year_country_gdp, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(aes(label = geo), hjust = -0.1, size = 3)+
|
||||
labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
year_country_gdp
|
||||
# ##################################################
|
||||
# House price index HPI
|
||||
df1
|
||||
house_price_index <- df1 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
house_price_index <- na.omit(house_price_index)
|
||||
|
||||
colnames(house_price_index)
|
||||
|
||||
df1 %>% group_by(geo) %>% str()
|
||||
|
||||
str(house_price_index)
|
||||
|
||||
house_price_index <- filter(house_price_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = house_price_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n() - 1),
|
||||
aes(label = geo, hjust = -1, size = 4))+
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
labs(x = "Rok", y = 'Indeks Cen nieruchomości [cena z 2015 roku = 100]')
|
||||
|
||||
|
||||
house_price_index
|
||||
# ######################################
|
||||
|
||||
# HICP - Harmonised Index for Consumer Prices
|
||||
df
|
||||
hicp_index <- df %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
hicp_index <- na.omit(hicp_index)
|
||||
|
||||
colnames(hicp_index)
|
||||
|
||||
df %>% group_by(geo) %>% str()
|
||||
|
||||
str(hicp_index)
|
||||
|
||||
hicp_index <- filter(hicp_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = hicp_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
|
||||
hicp_index
|
||||
|
||||
# ########################
|
||||
# Show data discounting inflation rate
|
||||
|
||||
# Merge the two data frames using the 'country' and 'date' columns
|
||||
merged_df <- merge(house_price_index, hicp_index, by = c("geo", "TIME_PERIOD"))
|
||||
|
||||
merged_df
|
||||
# Create a new column that divides 'value1' by 'value2'
|
||||
merged_df$house_prices_wo_hicp <- merged_df$OBS_VALUE.x / merged_df$OBS_VALUE.y*100
|
||||
|
||||
merged_df$TIME_PERIOD
|
||||
merged_df$compound_growth <- 1 * (1 + 0.02) ^ (1:(merged_df$TIME_PERIOD-2015))
|
||||
|
||||
# View the resulting merged data frame with the divided values
|
||||
merged_df
|
||||
merged_df <- na.omit(merged_df)
|
||||
|
||||
colnames(merged_df)
|
||||
|
||||
merged_df %>% group_by(geo) %>% str()
|
||||
|
||||
str(merged_df)
|
||||
|
||||
merged_df <- filter(merged_df, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
|
||||
geom_line(linetype="dotted", size=1) +
|
||||
geom_point(aes(x=TIME_PERIOD, y=house_prices_wo_hicp)) +
|
||||
geom_text(data = merged_df %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
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")) +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2)) +
|
||||
labs(x = "Year", y = 'Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]')
|
||||
|
||||
>>>>>>> 9cd7ec6d23058242fa1b48bf76dd80c927b5ef48
|
||||
library(dplyr)
|
||||
# install.packages("ggplot2")
|
||||
library(ggplot2)
|
||||
countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO')
|
||||
|
||||
df = read.csv(".//data//prc_hicp_aind_page_linear.csv")
|
||||
df[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
|
||||
df1 = read.csv(".//data//prc_hpi_a__custom_3617733_page_linear.csv")
|
||||
df1[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df1)
|
||||
|
||||
|
||||
df2 = read.csv(".//data//sdg_08_10_page_linear.csv")
|
||||
df2[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df2)
|
||||
|
||||
df3 = read.csv(".//data//tec00114_page_linear.csv")
|
||||
df3[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df3)
|
||||
print(df3)
|
||||
|
||||
# ##################################################
|
||||
# Single Country GDP graph
|
||||
|
||||
year_country_gdp <- df3 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
year_country_gdp <- na.omit(year_country_gdp)
|
||||
|
||||
colnames(year_country_gdp)
|
||||
|
||||
df3 %>% group_by(geo) %>% str()
|
||||
|
||||
str(year_country_gdp)
|
||||
|
||||
year_country_gdp <- filter(year_country_gdp, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(aes(label = geo), hjust = -0.1, size = 3)+
|
||||
labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
year_country_gdp
|
||||
# ##################################################
|
||||
# House price index HPI
|
||||
df1
|
||||
house_price_index <- df1 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
house_price_index <- na.omit(house_price_index)
|
||||
|
||||
colnames(house_price_index)
|
||||
|
||||
df1 %>% group_by(geo) %>% str()
|
||||
|
||||
str(house_price_index)
|
||||
|
||||
house_price_index <- filter(house_price_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = house_price_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n() - 1),
|
||||
aes(label = geo, hjust = -1, size = 4))+
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
labs(x = "Rok", y = 'Indeks Cen nieruchomości [cena z 2015 roku = 100]')
|
||||
|
||||
|
||||
house_price_index
|
||||
# ######################################
|
||||
|
||||
# HICP - Harmonised Index for Consumer Prices
|
||||
df
|
||||
hicp_index <- df %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
hicp_index <- na.omit(hicp_index)
|
||||
|
||||
colnames(hicp_index)
|
||||
|
||||
df %>% group_by(geo) %>% str()
|
||||
|
||||
str(hicp_index)
|
||||
|
||||
hicp_index <- filter(hicp_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = hicp_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
|
||||
hicp_index
|
||||
|
||||
# ########################
|
||||
# Show data discounting inflation rate
|
||||
|
||||
# Merge the two data frames using the 'country' and 'date' columns
|
||||
merged_df <- merge(house_price_index, hicp_index, by = c("geo", "TIME_PERIOD"))
|
||||
|
||||
merged_df
|
||||
# Create a new column that divides 'value1' by 'value2'
|
||||
merged_df$house_prices_wo_hicp <- merged_df$OBS_VALUE.x / merged_df$OBS_VALUE.y*100
|
||||
|
||||
merged_df$TIME_PERIOD
|
||||
merged_df$compound_growth <- 1 * (1 + 0.02) ^ (1:(merged_df$TIME_PERIOD-2015))
|
||||
|
||||
# View the resulting merged data frame with the divided values
|
||||
merged_df
|
||||
merged_df <- na.omit(merged_df)
|
||||
|
||||
colnames(merged_df)
|
||||
|
||||
merged_df %>% group_by(geo) %>% str()
|
||||
|
||||
str(merged_df)
|
||||
|
||||
merged_df <- filter(merged_df, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
|
||||
geom_line(linetype="dotted", size=1) +
|
||||
geom_point(aes(x=TIME_PERIOD, y=house_prices_wo_hicp)) +
|
||||
geom_text(data = merged_df %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
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")) +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2)) +
|
||||
labs(x = "Year", y = 'Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]')
|
219
projekt_1_housing_new.r
Normal file
219
projekt_1_housing_new.r
Normal file
@ -0,0 +1,219 @@
|
||||
library(dplyr)
|
||||
# install.packages("ggplot2")
|
||||
library(ggplot2)
|
||||
library(plotly)
|
||||
countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO', 'XD')
|
||||
|
||||
countries <- unique(map_df$geo)
|
||||
|
||||
df = read.csv(".//data//prc_hicp_aind_page_linear.csv")
|
||||
df[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
|
||||
df1 = read.csv(".//data//prc_hpi_a__custom_3617733_page_linear.csv")
|
||||
df1[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df1)
|
||||
|
||||
|
||||
df2 = read.csv(".//data//sdg_08_10_page_linear.csv")
|
||||
df2[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df2)
|
||||
|
||||
df3 = read.csv(".//data//tec00114_page_linear.csv")
|
||||
df3[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
|
||||
|
||||
colnames(df3)
|
||||
print(df3)
|
||||
|
||||
# ##################################################
|
||||
# Single Country GDP graph
|
||||
|
||||
year_country_gdp <- df3 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
year_country_gdp <- na.omit(year_country_gdp)
|
||||
|
||||
colnames(year_country_gdp)
|
||||
|
||||
df3 %>% group_by(geo) %>% str()
|
||||
|
||||
str(year_country_gdp)
|
||||
|
||||
year_country_gdp <- filter(year_country_gdp, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(aes(label = geo), hjust = -0.1, size = 3)+
|
||||
labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
plot <- ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>",
|
||||
"Rok: ", TIME_PERIOD, "<br>",
|
||||
"Warto?? wska?nika: ", OBS_VALUE))) +
|
||||
geom_line(aes(group = geo)) +
|
||||
geom_point() +
|
||||
labs(x = "Rok", y = 'PKB per capita w PPP [PPS_EU27_2020=100]') +
|
||||
scale_x_continuous(breaks = seq(2010, 2024, 2))
|
||||
|
||||
plotly_plot <- ggplotly(plot, tooltip = "text")
|
||||
|
||||
plotly_plot
|
||||
|
||||
|
||||
year_country_gdp
|
||||
# ##################################################
|
||||
# House price index HPI
|
||||
df1
|
||||
house_price_index <- df1 %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
house_price_index <- na.omit(house_price_index)
|
||||
|
||||
colnames(house_price_index)
|
||||
|
||||
df1 %>% group_by(geo) %>% str()
|
||||
|
||||
str(house_price_index)
|
||||
|
||||
house_price_index <- filter(house_price_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = house_price_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n() - 1),
|
||||
aes(label = geo, hjust = -1, size = 4))+
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
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>",
|
||||
"Rok: ", TIME_PERIOD, "<br>",
|
||||
"Warto?? wska?nika: ", OBS_VALUE))) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
scale_x_continuous(breaks = seq(2010, 2024, 2)) +
|
||||
labs(x = "Rok", y = 'Indeks Cen nieruchomo?ci [cena z 2015 roku = 100]')
|
||||
plotly_plot <- ggplotly(plot, tooltip = "text")
|
||||
for (i in 1:length(plotly_plot$x$data)) {
|
||||
if (plotly_plot$x$data[[i]]$type == "scatter") {
|
||||
plotly_plot$x$data[[i]]$mode <- "lines+markers"
|
||||
}
|
||||
}
|
||||
plotly_plot
|
||||
|
||||
house_price_index
|
||||
# ######################################
|
||||
|
||||
# HICP - Harmonised Index for Consumer Prices
|
||||
df
|
||||
hicp_index <- df %>% select( TIME_PERIOD, geo, OBS_VALUE)
|
||||
hicp_index <- na.omit(hicp_index)
|
||||
|
||||
colnames(hicp_index)
|
||||
|
||||
df %>% group_by(geo) %>% str()
|
||||
|
||||
str(hicp_index)
|
||||
|
||||
hicp_index <- filter(hicp_index, geo %in% countries)
|
||||
|
||||
# Plot
|
||||
ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
geom_text(data = hicp_index %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2))
|
||||
|
||||
|
||||
plot <- ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, text = paste("Kraj: ", geo, "<br>",
|
||||
"Rok: ", TIME_PERIOD, "<br>",
|
||||
"Warto?? wska?nika: ", OBS_VALUE))) +
|
||||
geom_line() +
|
||||
geom_point() +
|
||||
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
|
||||
scale_x_continuous(breaks = seq(2010, 2024, 2))
|
||||
|
||||
plotly_plot <- ggplotly(plot, tooltip = "text")
|
||||
|
||||
for (i in 1:length(plotly_plot$x$data)) {
|
||||
if (plotly_plot$x$data[[i]]$type == "scatter") {
|
||||
plotly_plot$x$data[[i]]$mode <- "lines+markers"
|
||||
}
|
||||
}
|
||||
plotly_plot
|
||||
|
||||
|
||||
hicp_index
|
||||
|
||||
# ########################
|
||||
# Show data discounting inflation rate
|
||||
|
||||
# Merge the two data frames using the 'country' and 'date' columns
|
||||
merged_df <- merge(house_price_index, hicp_index, by = c("geo", "TIME_PERIOD"))
|
||||
|
||||
merged_df
|
||||
# Create a new column that divides 'value1' by 'value2'
|
||||
merged_df$house_prices_wo_hicp <- merged_df$OBS_VALUE.x / merged_df$OBS_VALUE.y*100
|
||||
|
||||
merged_df$TIME_PERIOD
|
||||
merged_df$compound_growth <- 1 * (1 + 0.02) ^ (1:(merged_df$TIME_PERIOD-2015))
|
||||
|
||||
# View the resulting merged data frame with the divided values
|
||||
merged_df
|
||||
merged_df <- na.omit(merged_df)
|
||||
|
||||
colnames(merged_df)
|
||||
|
||||
merged_df %>% group_by(geo) %>% str()
|
||||
|
||||
str(merged_df)
|
||||
|
||||
unfiltered_df <- merged_df
|
||||
merged_df <- filter(merged_df, geo %in% countries)
|
||||
|
||||
|
||||
|
||||
|
||||
ggplot(merged_df, aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo)) +
|
||||
geom_line(linetype="dotted", size=1) +
|
||||
geom_point(aes(x=TIME_PERIOD, y=house_prices_wo_hicp)) +
|
||||
geom_text(data = merged_df %>%
|
||||
group_by(geo) %>%
|
||||
slice(n()),
|
||||
aes(label = geo, hjust = -0.2, size = 4)) +
|
||||
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")) +
|
||||
scale_x_continuous(breaks=seq(2010,2024,2)) +
|
||||
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,
|
||||
text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>",
|
||||
"Cena nieruchomo?ci: ", house_prices_wo_hicp))) +
|
||||
geom_line(aes(group = geo), linetype = "dotted", size = 1) +
|
||||
geom_point() +
|
||||
geom_text(data = merged_df %>% group_by(geo) %>% slice(n()),
|
||||
aes(label = "", hjust = -0.2, size = 4)) +
|
||||
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) +
|
||||
scale_x_continuous(breaks = seq(2010, 2024, 2)) +
|
||||
labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]")
|
||||
|
||||
final_plot
|
||||
|
||||
plotly_plot <- ggplotly(final_plot, tooltip = "text")
|
||||
|
||||
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
|
||||
|
@ -1,89 +1,88 @@
|
||||
library(tidyverse)
|
||||
library(eurostat)
|
||||
# install.packages("ggthemes")
|
||||
library(leaflet)
|
||||
library(sf)
|
||||
library(scales)
|
||||
library(cowplot)
|
||||
library(ggthemes)
|
||||
|
||||
library(RColorBrewer)
|
||||
|
||||
# Load results from project_1
|
||||
map_df = read.csv(".//data//compound_interest_housing.csv")
|
||||
map_df
|
||||
|
||||
# Load map/polygon data from eurostat
|
||||
SHP_0 <- get_eurostat_geospatial(resolution = 10,
|
||||
nuts_level = 0,
|
||||
year = 2016)
|
||||
|
||||
SHP_0 %>%
|
||||
ggplot() +
|
||||
geom_sf()
|
||||
|
||||
EU28 <- eu_countries %>%
|
||||
select(geo = code, name)
|
||||
|
||||
SHP_28 <- SHP_0 %>%
|
||||
select(geo = NUTS_ID, geometry) %>%
|
||||
inner_join(EU28, by = "geo") %>%
|
||||
arrange(geo) %>%
|
||||
st_as_sf()
|
||||
|
||||
SHP_28 %>%
|
||||
ggplot() +
|
||||
geom_sf() +
|
||||
scale_x_continuous(limits = c(-10, 35)) +
|
||||
scale_y_continuous(limits = c(35, 65))
|
||||
|
||||
# Join datasets
|
||||
|
||||
mapdata_new <- left_join(SHP_28, map_df, by="geo", relationship = "many-to-many")
|
||||
|
||||
# Delete Greece (null values)
|
||||
mapdata_new <- mapdata_new[-9,]
|
||||
|
||||
mapdata_new$wiki <- paste0( "https://en.wikipedia.org/wiki/", mapdata_new$name )
|
||||
|
||||
# Create a continuous palette function
|
||||
qpal <- colorQuantile("YlOrBr", mapdata_new$substr_house_prices_wo_hicp, n = 5)
|
||||
|
||||
qpal_colors <- unique(qpal(sort(mapdata_new$substr_house_prices_wo_hicp))) # hex codes
|
||||
qpal_labs <- quantile(mapdata_new$substr_house_prices_wo_hicp, seq(0, 1, .2)) # depends on n from pal
|
||||
qpal_labs <- paste(lag(qpal_labs), qpal_labs, sep = " - ")[-1] # first lag is NA
|
||||
|
||||
popup_content <- paste0( "<div style='text-align: center'>"
|
||||
, "_______________________________<br>"
|
||||
, "Country: ", mapdata_new$name, "<br><br>"
|
||||
, "</div>"
|
||||
|
||||
, "House prices index: ", mapdata_new$substr_house_prices_wo_hicp, "<br>"
|
||||
|
||||
, "Compound interest equivalent: ", mapdata_new$compound_interest, "%<br>"
|
||||
|
||||
, "<div style='text-align: center'>"
|
||||
, "<a href='", mapdata_new$wiki, "' target='_blank'>", "<br>"
|
||||
, "Click here to view wiki</a>", "<br>"
|
||||
, "</div>" )
|
||||
|
||||
map <- leaflet() %>%
|
||||
addProviderTiles(providers$CartoDB.Positron) %>%
|
||||
addPolygons(data=mapdata_new,
|
||||
fillOpacity = 0.6, # Przezroczystość
|
||||
stroke = TRUE, # Borders visible
|
||||
color = "grey", # Border color
|
||||
weight = 1,
|
||||
|
||||
fillColor = ~qpal(mapdata_new$substr_house_prices_wo_hicp),
|
||||
popup = popup_content,
|
||||
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE),
|
||||
) %>%
|
||||
setView( lat = 51, lng = 14, zoom = 4) %>%
|
||||
addLegend("bottomright", colors = qpal_colors,
|
||||
title = "<span style='white-space: pre-line;'> Real house prices \n index (2022) </span>",
|
||||
labels = qpal_labs,
|
||||
opacity = 1)
|
||||
|
||||
map
|
||||
|
||||
library(tidyverse)
|
||||
library(eurostat)
|
||||
library(leaflet)
|
||||
library(sf)
|
||||
library(scales)
|
||||
library(cowplot)
|
||||
library(ggthemes)
|
||||
|
||||
library(RColorBrewer)
|
||||
R.Version()
|
||||
|
||||
# Load results from project_1
|
||||
map_df = read.csv(".//data//compound_interest_housing.csv")
|
||||
map_df
|
||||
|
||||
# Load map/polygon data from eurostat
|
||||
SHP_0 <- get_eurostat_geospatial(resolution = 10,
|
||||
nuts_level = 0,
|
||||
year = 2016)
|
||||
|
||||
SHP_0 %>%
|
||||
ggplot() +
|
||||
geom_sf()
|
||||
|
||||
EU28 <- eu_countries %>%
|
||||
select(geo = code, name)
|
||||
|
||||
SHP_28 <- SHP_0 %>%
|
||||
select(geo = NUTS_ID, geometry) %>%
|
||||
inner_join(EU28, by = "geo") %>%
|
||||
arrange(geo) %>%
|
||||
st_as_sf()
|
||||
|
||||
SHP_28 %>%
|
||||
ggplot() +
|
||||
geom_sf() +
|
||||
scale_x_continuous(limits = c(-10, 35)) +
|
||||
scale_y_continuous(limits = c(35, 65))
|
||||
|
||||
# Join datasets
|
||||
|
||||
mapdata_new <- left_join(SHP_28, map_df, by="geo", relationship = "many-to-many")
|
||||
|
||||
# Delete Greece (null values)
|
||||
mapdata_new <- mapdata_new[-9,]
|
||||
mapdata_new
|
||||
mapdata_new$wiki <- paste0( "https://en.wikipedia.org/wiki/", mapdata_new$name )
|
||||
|
||||
# Create a continuous palette function
|
||||
qpal <- colorQuantile("YlOrBr", mapdata_new$substr_house_prices_wo_hicp, n = 5)
|
||||
|
||||
qpal_colors <- unique(qpal(sort(mapdata_new$substr_house_prices_wo_hicp))) # hex codes
|
||||
qpal_labs <- quantile(mapdata_new$substr_house_prices_wo_hicp, seq(0, 1, .2)) # depends on n from pal
|
||||
qpal_labs <- paste(lag(qpal_labs), qpal_labs, sep = " - ")[-1] # first lag is NA
|
||||
|
||||
popup_content <- paste0( "<div style='text-align: center'>"
|
||||
, "_______________________________<br>"
|
||||
, "Country: ", mapdata_new$name, "<br><br>"
|
||||
, "</div>"
|
||||
|
||||
, "House prices index: ", mapdata_new$substr_house_prices_wo_hicp, "<br>"
|
||||
|
||||
, "Compound interest equivalent: ", mapdata_new$compound_interest, "%<br>"
|
||||
|
||||
, "<div style='text-align: center'>"
|
||||
, "<a href='", mapdata_new$wiki, "' target='_blank'>", "<br>"
|
||||
, "Click here to view wiki</a>", "<br>"
|
||||
, "</div>" )
|
||||
|
||||
map <- leaflet() %>%
|
||||
addProviderTiles(providers$CartoDB.Positron) %>%
|
||||
addPolygons(data=mapdata_new,
|
||||
fillOpacity = 0.6, # Przezroczystość
|
||||
stroke = TRUE, # Borders visible
|
||||
color = "grey", # Border color
|
||||
weight = 1,
|
||||
|
||||
fillColor = ~qpal(mapdata_new$substr_house_prices_wo_hicp),
|
||||
popup = popup_content,
|
||||
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE),
|
||||
) %>%
|
||||
setView( lat = 53, lng = 14, zoom = 4) %>%
|
||||
addLegend("bottomright", colors = qpal_colors,
|
||||
title = "<span style='white-space: pre-line;'> Real house prices \n index (2022) </span>",
|
||||
labels = qpal_labs,
|
||||
opacity = 1)
|
||||
|
||||
map
|
||||
|
104
webapp.R
Normal file
104
webapp.R
Normal file
@ -0,0 +1,104 @@
|
||||
library(shiny)
|
||||
library(leaflet)
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
|
||||
# Frontend
|
||||
ui <- fluidPage(
|
||||
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
# Compound interest
|
||||
sliderInput("range", "Compound interest:",min = 0, max = 10, value = c(4,8)),textOutput("Compound interest slider"),
|
||||
|
||||
# Checkboxes
|
||||
checkboxGroupInput("countries", "Chosen countries:",
|
||||
choiceNames = unique(map_df$geo),
|
||||
choiceValues = unique(map_df$geo),
|
||||
selected = c("PL", "DE", "CZ")
|
||||
),
|
||||
|
||||
|
||||
width=3
|
||||
),
|
||||
|
||||
mainPanel(
|
||||
h1("Real house prices index"),
|
||||
|
||||
tabsetPanel(
|
||||
tabPanel("Plot", plotOutput("final_plot")),
|
||||
tabPanel("Map", leafletOutput("mymap")),
|
||||
tabPanel("Table", dataTableOutput('table'))
|
||||
),
|
||||
|
||||
width = 9
|
||||
),
|
||||
|
||||
fluid = TRUE
|
||||
)
|
||||
|
||||
|
||||
|
||||
)
|
||||
|
||||
# Backend
|
||||
server <- function(input, output, session) {
|
||||
|
||||
# Używanie wektora indeksu do indeksowania innych danych
|
||||
output$table <- renderDataTable(merged_df[,!names(merged_df) %in% c("OBS_VALUE.x", "OBS_VALUE.y")])
|
||||
|
||||
# Plot module
|
||||
output$final_plot <- renderPlot({
|
||||
|
||||
# final_plot <-
|
||||
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>",
|
||||
"Cena nieruchomości: ", house_prices_wo_hicp))) +
|
||||
geom_line(aes(group = geo), linetype = "dotted", size = 1) +
|
||||
geom_point() +
|
||||
geom_text(data = merged_df %>% group_by(geo) %>% slice(n()),
|
||||
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[2]/100)^(x-2015), aes(colour = "7% Compounding"), inherit.aes = FALSE) +
|
||||
scale_x_continuous(breaks = seq(2010, 2024, 2)) +
|
||||
# labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]") +
|
||||
theme( axis.title = element_blank() )
|
||||
|
||||
# ggplotly(final_plot, tooltip = "text")
|
||||
|
||||
#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
|
||||
output$mymap <- renderLeaflet({
|
||||
leaflet() %>%
|
||||
addProviderTiles(providers$CartoDB.Positron) %>%
|
||||
addPolygons(data=mapdata_new,
|
||||
fillOpacity = 0.6, # Przezroczystość
|
||||
stroke = TRUE, # Borders visible
|
||||
color = "grey", # Border color
|
||||
weight = 1,
|
||||
|
||||
fillColor = ~qpal(mapdata_new$substr_house_prices_wo_hicp),
|
||||
popup = popup_content,
|
||||
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE)
|
||||
) %>%
|
||||
setView( lat = 49, lng = 14, zoom = 4) %>%
|
||||
addLegend("bottomright", colors = qpal_colors,
|
||||
title = "<span style='white-space: pre-line;'> Real house prices \n index (2022) </span>",
|
||||
labels = qpal_labs,
|
||||
opacity = 1)
|
||||
}) # End of map module
|
||||
|
||||
}# End of server
|
||||
|
||||
# Run
|
||||
shinyApp(ui, server)
|
Loading…
Reference in New Issue
Block a user