From b3791c903c690465e5c11e26d62ee452fb4c3f47 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 14 Apr 2021 14:44:19 +0200 Subject: [PATCH] boxplot --- projekt.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/projekt.R b/projekt.R index 99f8414..9d3a1eb 100644 --- a/projekt.R +++ b/projekt.R @@ -43,3 +43,28 @@ ggplot(german_credit_risk , aes(x = factor(Job), fill = Purpose)) + scale_x_discrete(breaks = 0:3, labels=c("Unskilled, non-resident", "Unskilled, resident","Skilled","Highly skilled")) + labs(title="Credit count and purpose for different job statuses", x="Job status", y = "Credit count") + theme_minimal() + +#Wykres pudełkowy przedstawiający jakiej wielkości najczęściej ludzie biorą kredyty na poszczególne cele. +stat_box_data <- function(y) { + return( + data.frame( + y = max(german_credit_risk$Credit.amount), + label = paste('count =', length(y), '\n', + 'sum =', sum(y), '\n') + ) + ) +} + +german_credit_risk %>% + mutate(Purpose = reorder(Purpose, Credit.amount, sum)) %>% + ggplot(aes(x = Purpose, y = Credit.amount, fill = Purpose)) + + geom_boxplot(alpha = .7) + + guides(fill = "none") + + scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) + + stat_summary( + fun.data = stat_box_data, + geom = "text", + vjust = 1 + ) + + ylab("Credit amount") + + theme_bw()