The distribution of personal disposable income in Taiwan

ggplot語法

KY

2020-04-27

##借用語法
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2) 
library(viridis) 
## Loading required package: viridisLite
library(ggthemes)
library(tidyr)
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
##讀檔案,names重新命名
dta <-read.csv("C:/tmp/income_tw.csv",header = T)
names(dta)<-c("Income", "Count")
head(dta)
##               Income  Count
## 1  160,000 and under 807160
## 2 160,000 to 179,999 301650
## 3 180,000 to 199,999 313992
## 4 200,000 to 219,999 329290
## 5 220,000 to 239,999 369583
## 6 240,000 to 259,999 452671
##ggplot指令從XY軸開始作圖,Y值設定為點
p0 <- ggplot(data=dta, 
             aes(x=Count, y=Income))+
  geom_point(data=dta,aes(yend = Income))+
  stat_smooth(data=dta, 
              aes(yend = Income), 
              formula=y ~ x,
              method='lm', 
              se=FALSE)+
  labs(x='Count', y='Income',title="Relationship between Count and Income")+
  theme(legend.position='bottom')
## Warning: Ignoring unknown aesthetics: yend

## Warning: Ignoring unknown aesthetics: yend
p0