44 lines
1.5 KiB
R
44 lines
1.5 KiB
R
# Projekt 1: Przygotowanie wizualnej analizy danych z wykorzystaniem podstawowej biblioteki graficznej R i/lub biblioteki ggplot2
|
|
# zaladowanie bibliotek
|
|
library(Hmisc)
|
|
library(dplyr)
|
|
library(ggplot2)
|
|
library(RColorBrewer)
|
|
|
|
# zaladowanie danych
|
|
german_credit_risk <- read.csv("german_credit_data.csv", header = TRUE)
|
|
|
|
# sprawdzenie danych
|
|
head(german_credit_risk)
|
|
tail(german_credit_risk)
|
|
str(german_credit_risk)
|
|
summary(german_credit_risk)
|
|
describe(german_credit_risk)
|
|
|
|
# zmiana nazwy pierwszej kolumny
|
|
colnames(german_credit_risk)[1] <- "index"
|
|
|
|
min(german_credit_risk$Age)
|
|
na.omit(german_credit_risk)
|
|
|
|
# violin plot
|
|
ggplot(german_credit_risk, aes(x=Purpose, y=Age, fill=Sex)) +
|
|
geom_violin(trim=TRUE, position=position_dodge(1)) +
|
|
stat_summary(fun = mean, geom="point", shape=25, size=2) + #position=position_dodge(.9)
|
|
labs(title="Credit purpose by age", x="Purpose", y = "Age") +
|
|
scale_fill_brewer(palette="Accent") +
|
|
theme_minimal() +
|
|
theme(legend.position="bottom")
|
|
|
|
|
|
ggplot(german_credit_risk, aes(x = Duration, y = Credit.amount, color = Sex)) +
|
|
geom_point(size = 1.5) +
|
|
geom_smooth(se = FALSE, size = 1.5) +
|
|
labs(title="Credit amount for credit duration", x="Duration", y = "Amount") +
|
|
theme_minimal() +
|
|
theme(legend.position="bottom")
|
|
|
|
ggplot(german_credit_risk , aes(x = factor(Job), fill = Purpose)) +
|
|
geom_bar() +
|
|
scale_x_discrete(breaks = 0:3, labels=c("Unskilled, non-resident", "Unskilled, resident","Skilled","Highly skilled")) +
|
|
labs(title="Credit purposes for different job statuses", x="Duration", y = "Amount") |