Clear environment & load relevant libraries
TASK 1
df <- data.table(readRDS('flats.rds'))
df_1 <- df[,.(Area)]
plot_1 <- ggplot(df_1, aes(x=Area)) +
geom_histogram(bins = 40, color="white", fill="#006D77") +
theme_bw() +
labs(title = "Distribution of the Area of flats(m2)") +
theme(plot.title=element_text(hjust=0))
plot_1

TASK 2
df_2 <- df[!is.na(Condition),.(Price), by = Condition]
my_labels <- c('0 Ft', '250,000 Ft', '500,000 Ft', '750,000 Ft', '1,000,000 Ft')
plot_2 <- ggplot(df_2, aes(x=Price, group=Condition, fill=Condition)) +
geom_density(adjust=1, alpha=0.25) +
theme_bw() +
labs(title = "Price Distribution for Flats in Different Conditions") +
theme(plot.title=element_text(hjust=0))+
theme(legend.position = "top")+
guides(color = guide_legend(nrow = 1, byrow = TRUE))+
scale_x_continuous(labels=my_labels)
plot_2

TASK 3
df_3 <- df[!is.na(Condition),.(Area, Price), by = Condition]
my_labels_2 <- c('0 m2', '50 m2', '100 m2', '150 m2', '200 m2')
plot_3 <- ggplot(df_3, aes(x=Area, y=Price)) +
geom_point(adjust=0.5, alpha=0.4, aes(color=Condition)) +
theme_bw() +
geom_smooth(aes(color=Condition), method=lm, se=FALSE, fullrange=TRUE, size=1) +
labs(title = "How the condition of the flats effects price to area") +
theme(plot.title=element_text(hjust=0))+
theme(legend.position = "bottom")+
scale_x_continuous(labels=my_labels_2)+
scale_y_continuous(labels=my_labels)+
guides(color = guide_legend(nrow = 1, byrow = TRUE))
plot_3
## `geom_smooth()` using formula = 'y ~ x'

TASK 4
df_4 <- df[,.(Average_Price = mean(Price)), by = District][order(District)]
my_labels_3 <- c('0 Ft', '100,000 Ft', '200,000 Ft', '300,000 Ft', '400,000 Ft')
plot_4 <- ggplot(df_4, aes(x = factor(District), y = Average_Price), fill="#006D77") +
geom_bar(stat = "identity", fill="#006D77") +
theme_bw() +
labs(x="District", y="Average Price") +
theme(plot.title=element_text(hjust=0.5))+
scale_y_continuous(labels=my_labels_3)
plot_4

TASK 5
df_5 <- df[,.(Price), by = District][order(District)]
plot_5 <- ggplot(df_5,aes(factor(District), y = Price)) +
geom_violin(color="#006D77", fill="#66B7B0", alpha=0.7) +
theme_bw() +
labs(x="District", y="Price")
plot_5
