Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OECE Better Life Index 2013 중 소득격차에 따른 삶의 만족도 비교.
library(ggplot2)
BLI2013 <- read.csv("./data/BLI_2013.csv", stringsAsFactors=FALSE)
# 삶의 만족도 소득 상하위 10%, 전체 점수 추출
wealth <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("Total", "High", "Low"))
wealth$Inequality <- factor(wealth$Inequality, levels=c("High", "Total", "Low"))
# 소득차이에 따른 삶의 만족도
ggplot(wealth, aes(x=Value,
y=reorder(Country, Value), colour=Inequality)) +
geom_point(size=3, alpha=2/3) +
theme_bw() +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_line(colour="grey60", linetype="dashed")) +
ylab("") + xlab("Life satisfaction") + xlim(0,10)
# 소득 상위 10%와 하위 10%의 만족도 차이
wealth.high <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("High"))
wealth.low <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("Low"))
wealth.country <- merge(wealth.high, wealth.low, by=c("Country"))
wealth.country <- wealth.country[c("Country","Value.x", "Value.y")]
names(wealth.country) <- c("Country", "High", "Low")
wealth.country$diff <- with(wealth.country, High - Low)
wealth.country <- wealth.country[order(wealth.country$diff),]
wealth.country$color <- "1"
wealth.country[wealth.country$Country == "Korea","color"] <- "2"
wealth.country[wealth.country$Country == "OECD - Total","color"] <- "3"
write.csv(file='Life_wealth.csv', wealth.country, row.names=F)
ggplot(wealth.country,aes(x=1:37,y=diff, fill=color)) +
geom_bar(stat="identity", position="identity",colour="black", size=0.25) +
xlab("") + ylab("Difference of Life satisfactation") +
scale_fill_manual(values=c("#474749", "#CC1862", "#8CF226"), guide=FALSE) +
theme_bw() +
theme(axis.ticks = element_blank(), axis.text.x = element_blank())
## 부록 - 삶의 만족도 남녀 차이
# 삶의 만족도 남, 여, 전체 추출
gender <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("Men", "Total", "Women"))
gender$Inequality <- factor(gender$Inequality, levels=c("Women", "Total", "Men"))
# 삶의 만족도 성별차 그래프
ggplot(gender, aes(x=Value, y=reorder(Country, Value), colour=Inequality)) +
geom_point(size=3, alpha=2/3) +
theme_bw() +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.major.y = element_line(colour="grey60", linetype="dashed")) +
ylab("") + xlab("Life satisfaction") + xlim(0,10)
# 남녀 삶의 만족도차
gender.men <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("Men"))
gender.women <- subset(BLI2013, Indicator == "Life satisfaction" &
Inequality %in% c("Women"))
gender.country <- merge(gender.men, gender.women, by=c("Country"))
gender.country <- gender.country[c("Country","Value.x", "Value.y")]
names(gender.country) <- c("Country", "Men", "Women")
gender.country$diff <- with(gender.country, Women - Men)
gender.country <- gender.country[order(gender.country$diff),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.