Source of Data

Data Input

  • Graunt Life Table
graunt <- data.frame(x = c(0, seq(6, 76, by = 10)), lx.17th = c(100, 64, 40, 25, 16, 10, 6, 3, 1))

추가자료 입력

  • 같은 연령대의 1993년 미국 생명표 입력
us.93 <- data.frame(x = graunt$x, lx.93 = c(100, 99, 99, 98, 97, 95, 92, 84, 70))
  • us.93 데이터 프레임에서 lx.93 불러내는 다양한 방법. 각 방법마다 불러낸 객체는 다른 class에 속함.
us.93["lx.93"]
##   lx.93
## 1   100
## 2    99
## 3    99
## 4    98
## 5    97
## 6    95
## 7    92
## 8    84
## 9    70
us.93["lx.93"][[1]]
## [1] 100  99  99  98  97  95  92  84  70
us.93[2]
##   lx.93
## 1   100
## 2    99
## 3    99
## 4    98
## 5    97
## 6    95
## 7    92
## 8    84
## 9    70
us.93[2][[1]]
## [1] 100  99  99  98  97  95  92  84  70
us.93[, "lx.93"]
## [1] 100  99  99  98  97  95  92  84  70
us.93[, 2]
## [1] 100  99  99  98  97  95  92  84  70
us.93$lx.93
## [1] 100  99  99  98  97  95  92  84  70
us.93$lx
## [1] 100  99  99  98  97  95  92  84  70

자료 통합

  • 두 자료를 합쳐서 하나의 데이터프레임으로
(graunt.us <- data.frame(graunt, lx.93 = us.93$lx))
##    x lx.17th lx.93
## 1  0     100   100
## 2  6      64    99
## 3 16      40    99
## 4 26      25    98
## 5 36      16    97
## 6 46      10    95
## 7 56       6    92
## 8 66       3    84
## 9 76       1    70

Life Expectancy 기대 수명 계산

  • 기본원리는 다음 식에서 알 수 있다시피 생존곡선의 밑 면적이 기대값이라는 것임.
    • \(X \ge 0\), \(X \sim F(x)\) => \(X \equiv F^{-1}(U), U \sim U(0,1)\). 따라서,
    • \(E(X) = E\{F^{-1}(U)\} = \int_{0}^{1} F^{-1}(u)du = \int_0^{\infty} 1-F(x) dx = \int_{0}^{\infty} S(x) dx\)
  • 이 생존함수의 아래 면적을 계산하면, 그것이 곧 기대수명임. 각 코드가 수행하는 바를 알기 위하여 단계별로 돌려보면,

    1. 점과 선으로 Graunt 생존함수의 골격을 그리고,
# plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
plot(lx.17th ~ x, data = graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")

plot(graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")

2. x-축과 y-축에 관찰된 연령과 생존률 표시.
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx.17th, labels = graunt$lx.17th)

3. 0세, 76세를 알아보기 쉽게 점선으로 표시
plot(graunt$x, graunt$lx.17th, ann=F, xaxt="n", yaxt="n", type="b")
axis(side=1, at=graunt$x, labels=graunt$x)
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th)
abline(v = c(0, 76), lty = 2)

  • polygon()에 필요한 좌표 설정. (Clockwise)
(graunt.x <- c(graunt$x, 0))
##  [1]  0  6 16 26 36 46 56 66 76  0
(graunt.y <- c(graunt$lx.17th, 0))
##  [1] 100  64  40  25  16  10   6   3   1   0
4. 빗금칠
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx.17th, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
polygon(graunt.x, graunt.y, density = 15, angle = 135)

5. 알아보기 쉽게 격자 설정
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx.17th, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
polygon(graunt.x, graunt.y, density=15)
abline(v = graunt$x, lty = 2)

6. 제목과 x-축, y-축의 라벨 입력.
par(family = "Apple SD Gothic Neo")
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx.17th, labels = graunt$lx.17th)
abline(v = c(0, 76), lty=2)
polygon(graunt.x, graunt.y, density=15)
abline(v = graunt$x, lty = 2)
title(main = "John Graunt의 생존 곡선", xlab = "연령(세)", ylab = "생존률(%)")

Area under the curve

  • 곡선 아랫 부분의 면적이 사다리꼴 면적들의 합인 점에 착안하면, 그 면적은
    • \(\sum_{i=1}^{n-1} (x_{i+1}-x_i)\times\frac{1}{2}(y_i + y_{i+1})\).
    • 이는 diff(), head()tail()을 이용하여 간단한 식으로 표현할 수 있음.
area.R <- function(x, y) {
  sum(diff(x) * (head(y, -1) + tail(y, -1))/2)
  }
area.R(graunt$x, graunt$lx.17th) / 100
## [1] 18.17

Comparison with US 1993 lifetable

plot(graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side=2, at=graunt$lx, labels=graunt$lx.17th)
abline(v=c(0, 76), lty=2)

2. 1993년 미국의 생존함수 추가
plot(graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")

3. 1993년 미국인의 76세까지 생존률 70%를 점선으로 표시. 
plot(graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")
abline(h = 70, lty = 2)

4. 70% 눈금에 `las = 1`을 써서 수평하게 표시. 
plot(graunt, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")
abline(h = 70, lty = 2)
axis(side = 2, at = 70, labels = 70, las = 1)

polygon()에 필요한 좌표 설정.

us.graunt.x <- c(us.93$x, rev(graunt$x))
us.graunt.y <- c(us.93$lx.93, rev(graunt$lx.17th))
5. 두 곡선의 사이를 빗금으로 표시.
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")
abline(h = 70, lty = 2)
axis(side = 2, at = 70, labels = 70, las = 1)
polygon(us.graunt.x, us.graunt.y, density = 15, col = "red", border = NA)

6. 알아보기 쉽게 격자 표시
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")
abline(h = 70, lty = 2)
axis(side = 2, at = 70, labels = 70, las = 1)
polygon(us.graunt.x, us.graunt.y, density = 15, col = "red", border = NA)
abline(v = graunt$x, lty = 2)

7. 제목과 x-축, y-축의 라벨 입력.
plot(graunt$x, graunt$lx.17th, ann = F, xaxt = "n", yaxt = "n", type = "b")
axis(side = 1, at = graunt$x, labels = graunt$x)
axis(side = 2, at = graunt$lx, labels = graunt$lx.17th)
abline(v = c(0, 76), lty = 2)
lines(us.93$x, us.93$lx.93, type = "b")
abline(h = 70, lty = 2)
axis(side = 2, at = 70, labels = 70, las = 1)
polygon(us.graunt.x, us.graunt.y, density = 15, col = "red", border = NA)
abline(v = graunt$x, lty = 2)
title(main="Graunt와 1993년 미국의 생존 곡선", xlab="연령(세)", ylab="생존률(%)")

Life expectancy

  • 1993 미국 생존함수의 밑면적(기대수명)은
area.R(us.93$x, us.93$lx.93)/100
## [1] 70.92
  • 따라서 빗금친 부분의 면적, 즉 기대수명의 차이는
area.R(us.93$x, us.93$lx.93)/100 - area.R(graunt$x, graunt$lx.17th)/100
## [1] 52.75

Comparison with Halley’s lifetable

Halley의 lifetable data

age <- 0:84
lx <- c(1238, 1000, 855, 798, 760, 732, 710, 692, 680, 670, 661, 653, 646, 640, 634, 628, 622, 616, 610, 604, 598, 592, 586, 579, 573, 567, 560, 553, 546, 539, 531, 523, 515, 507, 499, 490, 481, 472, 463, 454, 445, 436, 427, 417, 407, 397, 387, 377, 367, 357, 346, 335, 324, 313, 302, 292, 282, 272, 262, 252, 242, 232, 222, 212, 202, 192, 182, 172, 162, 152, 142, 131, 120, 109, 98, 88, 78, 68, 58, 50, 41, 34, 28, 23, 20)
length(lx)
## [1] 85
halley <- data.frame(age, lx)
halley$px <- round(halley$lx/1238*100, digits = 1)
halley
##    age   lx    px
## 1    0 1238 100.0
## 2    1 1000  80.8
## 3    2  855  69.1
## 4    3  798  64.5
## 5    4  760  61.4
## 6    5  732  59.1
## 7    6  710  57.4
## 8    7  692  55.9
## 9    8  680  54.9
## 10   9  670  54.1
## 11  10  661  53.4
## 12  11  653  52.7
## 13  12  646  52.2
## 14  13  640  51.7
## 15  14  634  51.2
## 16  15  628  50.7
## 17  16  622  50.2
## 18  17  616  49.8
## 19  18  610  49.3
## 20  19  604  48.8
## 21  20  598  48.3
## 22  21  592  47.8
## 23  22  586  47.3
## 24  23  579  46.8
## 25  24  573  46.3
## 26  25  567  45.8
## 27  26  560  45.2
## 28  27  553  44.7
## 29  28  546  44.1
## 30  29  539  43.5
## 31  30  531  42.9
## 32  31  523  42.2
## 33  32  515  41.6
## 34  33  507  41.0
## 35  34  499  40.3
## 36  35  490  39.6
## 37  36  481  38.9
## 38  37  472  38.1
## 39  38  463  37.4
## 40  39  454  36.7
## 41  40  445  35.9
## 42  41  436  35.2
## 43  42  427  34.5
## 44  43  417  33.7
## 45  44  407  32.9
## 46  45  397  32.1
## 47  46  387  31.3
## 48  47  377  30.5
## 49  48  367  29.6
## 50  49  357  28.8
## 51  50  346  27.9
## 52  51  335  27.1
## 53  52  324  26.2
## 54  53  313  25.3
## 55  54  302  24.4
## 56  55  292  23.6
## 57  56  282  22.8
## 58  57  272  22.0
## 59  58  262  21.2
## 60  59  252  20.4
## 61  60  242  19.5
## 62  61  232  18.7
## 63  62  222  17.9
## 64  63  212  17.1
## 65  64  202  16.3
## 66  65  192  15.5
## 67  66  182  14.7
## 68  67  172  13.9
## 69  68  162  13.1
## 70  69  152  12.3
## 71  70  142  11.5
## 72  71  131  10.6
## 73  72  120   9.7
## 74  73  109   8.8
## 75  74   98   7.9
## 76  75   88   7.1
## 77  76   78   6.3
## 78  77   68   5.5
## 79  78   58   4.7
## 80  79   50   4.0
## 81  80   41   3.3
## 82  81   34   2.7
## 83  82   28   2.3
## 84  83   23   1.9
## 85  84   20   1.6

With Base Plot

plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")

2. Halley의 생존곡선에 Graunt의 생명표에 나오는 연령에서 관찰되는 생존률을 같은 모양의 점으로 표시한다.
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)

3. Graunt의 생존곡선을 추가한다. 
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")

4. x-축과 y-축에 라벨을 넣는다. y축 라벨을 보기 쉽게 `las=1` 적용.
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)

5. 0세, 76세, 85세에 점선으로 수직선 설치
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)
abline(v=c(0, 76, 85), lty=2)

5. 적절한 좌표에 각 생존함수의 개발자를 표시하여 구분.
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)
abline(v=c(0, 76, 85), lty=2)
text(x = c(16, 36), y=c(20, 50), label=c("Graunt", "Halley"))

6. 전체 제목과 x-축 및 y-축의 라벨 표시.
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)
abline(v=c(0, 76, 85), lty=2)
text(x = c(16, 36), y=c(20, 50), label=c("Graunt", "Halley"))
title(main="Graunt와 Halley의 생존 곡선 비교", xlab="연령(세)", ylab="생존률(%)")

Polygon

poly.1.x<-c(0:10, 10.8, 6, 0)
poly.1.y<-c(halley$px[1:11], 52.8, graunt$lx.17th[2:1])
* 교점 아랫부분의 좌표
poly.2.x <- c(10.8, graunt$x[3:9], rev(halley$age[12:85]))
poly.2.y <- c(52.8, graunt$lx.17th[3:9], rev(halley$px[12:85]))
7. 차이를 비교하기 쉽도록 빗금으로 표시하되, 윗부분 먼저 표시. 
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)
abline(v=c(0, 76, 85), lty=2)
text(x = c(16, 36), y=c(20, 50), label=c("Graunt", "Halley"))
title(main="Graunt와 Halley의 생존 곡선 비교", xlab="연령(세)", ylab="생존률(%)")
polygon(poly.1.x, poly.1.y, angle=45, density=15, col="blue")

8. 아랫부분 표시. 
plot(px ~ age, data = halley, ann = F, xaxt = "n", yaxt = "n", type="l")
points(px[age %in% graunt$x]~age[age %in% graunt$x], data=halley)
lines(lx.17th~x, data=graunt, type="b")
axis(side=1, at=c(graunt$x, 85), labels=c(graunt$x, 85))
axis(side=2, at=graunt$lx.17th, labels=graunt$lx.17th, las=1)
abline(v=c(0, 76, 85), lty=2)
text(x = c(16, 36), y=c(20, 50), label=c("Graunt", "Halley"))
title(main="Graunt와 Halley의 생존 곡선 비교", xlab="연령(세)", ylab="생존률(%)")
polygon(poly.1.x, poly.1.y, angle=45, density=15, col="blue")
polygon(poly.2.x, poly.2.y, angle=45, density=15, col="red")

Life expectancy

  • 기대수명은 어떻게 차이나는가?
(ex.halley <- area.R(halley$age, halley$px)/100)
## [1] 27.872
(ex.graunt <- area.R(graunt$x, graunt$lx.17th)/100)
## [1] 18.17

ggplot 으로 그려본다면

To add Korean Fonts to theme

  • 그림의 전체 제목과 x-축, y-축, 범례를 한글로 바꿔 주기 위하여 extrafont 패키지를 설치하고 시스템 폰트를 등록한 후 theme()을 한글로 설정하여 저장.
library(ggplot2)
theme.kr <- theme(axis.title.x = element_text(family = "HCR Dotum LVT"),
                  axis.title.y = element_text(family = "HCR Dotum LVT"),
                  axis.text.x = element_text(family = "HCR Dotum LVT"),
                  axis.text.y = element_text(family = "HCR Dotum LVT"),
                  plot.title = element_text(family = "HCR Dotum LVT"),
                  legend.title = element_text(family = "HCR Dotum LVT"),
                  legend.text = element_text(family = "HCR Dotum LVT"))

Reshape

  • wide format을 long format으로 바꾸기 위해서 ‘reshape2’ 패키지 등록
library(reshape2)
  • 다음 구조를 명확히 이해.
graunt.melt <- melt(graunt.us, id.vars = "x", measure.vars = c("lx.17th", "lx.93"), value.name = "lx", variable.name = "times")
graunt.melt
##     x   times  lx
## 1   0 lx.17th 100
## 2   6 lx.17th  64
## 3  16 lx.17th  40
## 4  26 lx.17th  25
## 5  36 lx.17th  16
## 6  46 lx.17th  10
## 7  56 lx.17th   6
## 8  66 lx.17th   3
## 9  76 lx.17th   1
## 10  0   lx.93 100
## 11  6   lx.93  99
## 12 16   lx.93  99
## 13 26   lx.93  98
## 14 36   lx.93  97
## 15 46   lx.93  95
## 16 56   lx.93  92
## 17 66   lx.93  84
## 18 76   lx.93  70
str(graunt.melt)
## 'data.frame':    18 obs. of  3 variables:
##  $ x    : num  0 6 16 26 36 46 56 66 76 0 ...
##  $ times: Factor w/ 2 levels "lx.17th","lx.93": 1 1 1 1 1 1 1 1 1 2 ...
##  $ lx   : num  100 64 40 25 16 10 6 3 1 100 ...
  • 17세기 생명표와 1993년 생명표를 times factor로 구분
levels(graunt.melt$times) <- c("17th", "1993")
str(graunt.melt)
## 'data.frame':    18 obs. of  3 variables:
##  $ x    : num  0 6 16 26 36 46 56 66 76 0 ...
##  $ times: Factor w/ 2 levels "17th","1993": 1 1 1 1 1 1 1 1 1 2 ...
##  $ lx   : num  100 64 40 25 16 10 6 3 1 100 ...

ggplot

Points and Lines

  • ggplot의 구조를 이해하기 쉽도록 가능한 단계별로 작업하고 저장. geom_polygon 작업에서 data.frameaes가 바뀌므로 ggplot()을 비워놓은 점에 유의.
g1 <- ggplot() + geom_point(data = graunt.melt, aes(x = x, y = lx, colour = times))
g1

g2 <- g1 + geom_line(data = graunt.melt, aes(x = x, y = lx, colour = times))
g2

g3 <- g2 + theme_bw()
g3

Polygon

  • polygon 으로 두 생명곡선의 차이를 드러내기 위해서는 polygon의 좌표를 나타내는 별도의 데이터 프레임이 필요함.
graunt.poly <- data.frame(x = graunt.melt[c(1:9, 18:10), 1], y = graunt.melt[c(1:9, 18:10), 3])
graunt.poly
##     x   y
## 1   0 100
## 2   6  64
## 3  16  40
## 4  26  25
## 5  36  16
## 6  46  10
## 7  56   6
## 8  66   3
## 9  76   1
## 10 76  70
## 11 66  84
## 12 56  92
## 13 46  95
## 14 36  97
## 15 26  98
## 16 16  99
## 17  6  99
## 18  0 100
p3 <- g3 + geom_polygon(data = graunt.poly, aes(x = x, y = y), alpha = 0.3, fill = "red")
p3

p4 <- p3 + guides(colour = "none")
p4

Add Korean Annotations

Points and Lines

1. 지난 시간에 그린 g3에 theme.kr을 적용하고, x-축과 y-축의 라벨 수정. 
(g4 <- g3 + theme.kr +
   xlab("연령") + ylab("생존률(%)"))

2. 전체 제목 추가
(g4 <- g3 + theme.kr +
   xlab("연령") + ylab("생존률(%)") +
   ggtitle("Graunt 시대와 1993년 미국의 생존함수 비교"))

3. 범례 제목 한글로 수정.
(g4 <- g3 + theme.kr +
   xlab("연령") + ylab("생존률(%)") +
   ggtitle("Graunt 시대와 1993년 미국의 생존함수 비교") +
   labs(colour = "시기"))

4. 범례의 항목 한글로 수정.
(g4 <- g3 + theme.kr +
   xlab("연령") + ylab("생존률(%)") +
   ggtitle("Graunt 시대와 1993년 미국의 생존함수 비교") +
   labs(colour="시기") +
   scale_colour_discrete(labels = c("Graunt 시대", "1993년 미국")))

  • 범례를 그림 안쪽에 위치시키려면,
(g5 <- g4 + theme(legend.position = c(0.8, 0.5)))

  • x-축의 눈금과 y-축의 눈금을 낯익은 값들로 조정.
(g6 <- g5 + scale_x_continuous(breaks = graunt$x) + scale_y_continuous(breaks = graunt$lx.17th))

Polygon

  • polygon 으로 그린 최종 작품에 한글 정보 입력.
    1. p4에서 출발.
p4

2. 앞과 같은 방법으로 타이틀과 범례에 한글 입력.
(p5 <- p4 + theme.kr +
   xlab("연령") + ylab("생존률(%)") +
   ggtitle("Graunt 시대와 1993년 미국의 기대수명 차이"))

3. "Graunt 시대", "1993년 미국", "기대수명의 차이"를 각각 필요한 위치 삽입.
(p6 <- p5 + annotate("text", x = c(20, 40, 70), y = c(20, 60, 90), label=c("Graunt 시대", "기대수명의 차이", "1993년 미국"), family="HCR Dotum LVT"))

4. x-축의 눈금과 y-축의 눈금을 낯익은 값들로 조정.
(p7 <- p6 + scale_x_continuous(breaks = graunt$x) + scale_y_continuous(breaks = graunt$lx.17th))

theme.kr

  • structure and class of theme.kr
# theme.kr
str(theme.kr)
## List of 7
##  $ axis.title.x:List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y:List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x :List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y :List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.title  :List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.title:List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.text :List of 8
##   ..$ family    : chr "HCR Dotum LVT"
##   ..$ face      : NULL
##   ..$ colour    : NULL
##   ..$ size      : NULL
##   ..$ hjust     : NULL
##   ..$ vjust     : NULL
##   ..$ angle     : NULL
##   ..$ lineheight: NULL
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi FALSE
class(theme.kr)
## [1] "theme" "gg"

dump() and source()

  • 이 세션에서 만든 함수를 어떻게 저장하는 지 유의. 불러올 때는 source() 사용.
dump("theme.kr", file="theme_kr.R")
dump("area.R", file = "area.R")
save.image("graunt_halley_160328.rda")