Upload files to ''

This commit is contained in:
Paweł Lewicki 2023-05-30 14:42:23 +02:00
parent e9dc172402
commit 9cd7ec6d23
2 changed files with 183 additions and 181 deletions

View File

@ -1,143 +1,143 @@
library(dplyr) library(dplyr)
# install.packages("ggplot2") # install.packages("ggplot2")
library(ggplot2) library(ggplot2)
countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO') countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO')
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")]
df1 = read.csv(".//data//prc_hpi_a__custom_3617733_page_linear.csv") df1 = read.csv(".//data//prc_hpi_a__custom_3617733_page_linear.csv")
df1[,c("geo", "TIME_PERIOD", "OBS_VALUE")] df1[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
colnames(df1) colnames(df1)
df2 = read.csv(".//data//sdg_08_10_page_linear.csv") df2 = read.csv(".//data//sdg_08_10_page_linear.csv")
df2[,c("geo", "TIME_PERIOD", "OBS_VALUE")] df2[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
colnames(df2) colnames(df2)
df3 = read.csv(".//data//tec00114_page_linear.csv") df3 = read.csv(".//data//tec00114_page_linear.csv")
df3[,c("geo", "TIME_PERIOD", "OBS_VALUE")] df3[,c("geo", "TIME_PERIOD", "OBS_VALUE")]
colnames(df3) colnames(df3)
print(df3) print(df3)
# ################################################## # ##################################################
# Single Country GDP graph # Single Country GDP graph
year_country_gdp <- df3 %>% select( TIME_PERIOD, geo, OBS_VALUE) year_country_gdp <- df3 %>% select( TIME_PERIOD, geo, OBS_VALUE)
year_country_gdp <- na.omit(year_country_gdp) year_country_gdp <- na.omit(year_country_gdp)
colnames(year_country_gdp) colnames(year_country_gdp)
df3 %>% group_by(geo) %>% str() df3 %>% group_by(geo) %>% str()
str(year_country_gdp) str(year_country_gdp)
year_country_gdp <- filter(year_country_gdp, geo %in% countries) year_country_gdp <- filter(year_country_gdp, geo %in% countries)
# Plot # Plot
ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) + ggplot(year_country_gdp, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
geom_text(aes(label = geo), hjust = -0.1, size = 3)+ geom_text(aes(label = geo), hjust = -0.1, size = 3)+
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]') +
scale_x_continuous(breaks=seq(2010,2024,2)) scale_x_continuous(breaks=seq(2010,2024,2))
year_country_gdp year_country_gdp
# ################################################## # ##################################################
# House price index HPI # House price index HPI
df1 df1
house_price_index <- df1 %>% select( TIME_PERIOD, geo, OBS_VALUE) house_price_index <- df1 %>% select( TIME_PERIOD, geo, OBS_VALUE)
house_price_index <- na.omit(house_price_index) house_price_index <- na.omit(house_price_index)
colnames(house_price_index) colnames(house_price_index)
df1 %>% group_by(geo) %>% str() df1 %>% group_by(geo) %>% str()
str(house_price_index) str(house_price_index)
house_price_index <- filter(house_price_index, geo %in% countries) house_price_index <- filter(house_price_index, geo %in% countries)
# Plot # Plot
ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) + ggplot(house_price_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
geom_text(data = house_price_index %>% geom_text(data = house_price_index %>%
group_by(geo) %>% group_by(geo) %>%
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]')
house_price_index house_price_index
# ###################################### # ######################################
# HICP - Harmonised Index for Consumer Prices # HICP - Harmonised Index for Consumer Prices
df df
hicp_index <- df %>% select( TIME_PERIOD, geo, OBS_VALUE) hicp_index <- df %>% select( TIME_PERIOD, geo, OBS_VALUE)
hicp_index <- na.omit(hicp_index) hicp_index <- na.omit(hicp_index)
colnames(hicp_index) colnames(hicp_index)
df %>% group_by(geo) %>% str() df %>% group_by(geo) %>% str()
str(hicp_index) str(hicp_index)
hicp_index <- filter(hicp_index, geo %in% countries) hicp_index <- filter(hicp_index, geo %in% countries)
# Plot # Plot
ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) + ggplot(hicp_index, aes(x = TIME_PERIOD, y = OBS_VALUE, color = geo, label = geo)) +
geom_line() + geom_line() +
geom_point() + geom_point() +
geom_text(data = hicp_index %>% geom_text(data = hicp_index %>%
group_by(geo) %>% group_by(geo) %>%
slice(n()), slice(n()),
aes(label = geo, hjust = -0.2, size = 4)) + aes(label = geo, hjust = -0.2, size = 4)) +
labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') + labs(x = "Rok", y = 'Indeks inflacji konsumenckiej HICP [2015 = 100]') +
scale_x_continuous(breaks=seq(2010,2024,2)) scale_x_continuous(breaks=seq(2010,2024,2))
hicp_index hicp_index
# ######################## # ########################
# Show data discounting inflation rate # Show data discounting inflation rate
# Merge the two data frames using the 'country' and 'date' columns # 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 <- merge(house_price_index, hicp_index, by = c("geo", "TIME_PERIOD"))
merged_df merged_df
# Create a new column that divides 'value1' by 'value2' # 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$house_prices_wo_hicp <- merged_df$OBS_VALUE.x / merged_df$OBS_VALUE.y*100
merged_df$TIME_PERIOD merged_df$TIME_PERIOD
merged_df$compound_growth <- 1 * (1 + 0.02) ^ (1:(merged_df$TIME_PERIOD-2015)) merged_df$compound_growth <- 1 * (1 + 0.02) ^ (1:(merged_df$TIME_PERIOD-2015))
# View the resulting merged data frame with the divided values # View the resulting merged data frame with the divided values
merged_df merged_df
merged_df <- na.omit(merged_df) merged_df <- na.omit(merged_df)
colnames(merged_df) colnames(merged_df)
merged_df %>% group_by(geo) %>% str() merged_df %>% group_by(geo) %>% str()
str(merged_df) str(merged_df)
merged_df <- filter(merged_df, geo %in% countries) merged_df <- filter(merged_df, geo %in% countries)
# Plot # Plot
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)) +
geom_text(data = merged_df %>% geom_text(data = merged_df %>%
group_by(geo) %>% group_by(geo) %>%
slice(n()), slice(n()),
aes(label = geo, hjust = -0.2, size = 4)) + 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.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]')

View File

@ -1,38 +1,40 @@
library(dplyr) library(dplyr)
library(tidyverse) library(tidyverse)
# install.packages("colorRamps") # install.packages("colorRamps")
library(ggplot2) library(ggplot2)
library(colorRamps) library(colorRamps)
# countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO') # countries = c( 'PL', 'DE', 'CZ', 'NL', 'RO')
map_df = read.csv(".//data//compound_interest_housing.csv") map_df = read.csv(".//data//compound_interest_housing.csv")
map_df map_df
ggplot(map_df, aes(x = TIME_PERIOD, y = compound_interest, color = geo)) + ggplot(map_df, aes(x = TIME_PERIOD, y = compound_interest, color = geo)) +
geom_point(aes(x=TIME_PERIOD, y=compound_interest)) + geom_point(aes(x=TIME_PERIOD, y=compound_interest)) +
geom_text(data = map_df %>% geom_text(data = map_df %>%
group_by(geo) %>% group_by(geo) %>%
slice(n()), slice(n()),
aes(label = geo, hjust = -0.2, size = 4)) + aes(label = geo, hjust = -0.2, size = 4)) +
scale_x_continuous(breaks=seq(2010,2024,2)) + scale_x_continuous(breaks=seq(2010,2024,2)) +
labs(x = "Year", y = 'wartość mieszkania jako % składany powyżej inflacji') labs(x = "Year", y = 'wartość mieszkania jako % składany powyżej inflacji')
# filter data to have both coordinates and value # filter data to have both coordinates and value
geo_list <- c("Belarus", "Greece", "Latvia", "Albania", geo_list <- c("Belarus", "Greece", "Latvia", "Albania",
"Switzerland", "Bosnia and Herzegovina", "Ukraine", "Switzerland", "Bosnia and Herzegovina", "Ukraine",
"UK", "Turkey", "Serbia", "Kosovo", "Moldova", "North Macedonia", "UK", "Turkey", "Serbia", "Kosovo", "Moldova", "North Macedonia",
"Montenegro", "cyprus", "Malta") "Montenegro", "Cyprus", "Malta", "Georgia", "Armenia")
mapdata <- map_data("world") mapdata <- map_data("world")
mapdata1 <- left_join(mapdata, map_df, by="region", relationship = "many-to-many") mapdata1 <- left_join(mapdata, map_df, by="region", relationship = "many-to-many")
mapdata2 <- mapdata1 %>% filter(!is.na(mapdata1$compound_interest)| mapdata1$region %in% geo_list) mapdata2 <- mapdata1 %>% filter(!is.na(mapdata1$compound_interest)| mapdata1$region %in% geo_list)
mapdata2 mapdata2
map1 <- ggplot(mapdata2, aes(x = long, y = lat, group = group)) + map1 <- ggplot(mapdata2, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(fill = compound_interest), color = "black") + geom_polygon(aes(fill = compound_interest), color = "black") +
scale_fill_gradient(name="compound interest", low = "white", high = "black", na.value = "yellow") #geom_text(aes(label = region), size = 3, nudge_y = 1) + # Add labels
#scale_fill_gradient(name="compound interest", low = "white", high = "black", na.value = "yellow") +
map1 scale_fill_viridis_c(name="compound interest", option = "plasma", trans = "sqrt", na.value = "grey") + # colorblind-friendly palette
labs(title = "World Map with Compound Interest") # Set plot title
map1