library(fairml)
library(ggplot2)
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(ggExtra)
library(gridExtra)
library(viridis)
## Загрузка требуемого пакета: viridisLite
library(grid)
library(dplyr)
##
## Присоединяю пакет: 'dplyr'
## Следующий объект скрыт от 'package:gridExtra':
##
## combine
## Следующие объекты скрыты от 'package:stats':
##
## filter, lag
## Следующие объекты скрыты от 'package:base':
##
## intersect, setdiff, setequal, union
german.credit <- fairml::german.credit
table(german.credit$Job)
##
## management / self-employed / highly qualified employee / officer
## 148
## skilled employee / official
## 630
## unemployed / unskilled - non-resident
## 22
## unskilled - resident
## 200
german.credit$Job <- ifelse(german.credit$Job == "management / self-employed / highly qualified employee / officer", "management",
ifelse(german.credit$Job == "skilled employee / official", "skilled employee",
ifelse(german.credit$Job == "unemployed / unskilled - non-resident", "non-resident unemployed", "resident unskilled")))
library(ggExtra)
df1 <- german.credit %>% group_by(Housing, Job) %>%
summarise(count = n()) %>% mutate(per = round(count/sum(count),2)*100)
## `summarise()` has grouped output by 'Housing'. You can override using the
## `.groups` argument.
graph1 <- ggplot(df1, aes(x = "", y = count, fill = Housing)) +
geom_col(position = "fill") + coord_polar("y", start = 80) +
facet_wrap(~Job) + scale_fill_manual(values = c("#192D45", "#163B88", "#748CDB"))+
xlab("") + ylab("") + geom_text(aes(label = count),
position = position_fill(vjust = 0.5), color = "white") +
theme_classic() + theme(axis.text.x = element_blank(),
strip.text = element_text(size = 8))
graph2 <- ggplot(data = german.credit, aes(Housing)) +
geom_bar(aes(fill = Housing)) +
theme_classic() + scale_fill_manual(values = c("#192D45", "#163B88", "#748CDB")) +
theme(legend.position = "none") + ylab("Количество") + xlab("") + geom_label(stat = "count", aes(label = ..count..))
grid.arrange(graph2,graph1, ncol = 2, top = textGrob("Отображение владения домом по всей выборке
и внутри подвыборок профессий"))
