연륜연대분석 결과를 쉽게 표현하기 위해 새롭게 간트차트를 활용해서 그래프를 작성
그래프에서 표현하고자 항목은
1. 심변재 구분
2. 연륜수
3. 최외각연륜 표기
library(ggplot2)
library(ggalt)
library(dplyr)
setwd("c:/R/1400_R_Timeline/")
den <- read.csv("dendro.csv", stringsAsFactors=FALSE)
arrange(den, no) %>%
mutate(name=factor(name, levels=c(" ", rev(name), " "))) -> den
treerings <- function(x) {
x <- sprintf("%d", round(x))
x
}
gg <- ggplot()
gg <- gg + geom_segment(data=den, size=10, color="#D2691E",
aes(x=start_year, xend=end_year, y=name, yend=name))
gg <- gg + geom_segment(data=den, size=10, color="#FFDAB9",
aes(x=end_year-sap, xend=end_year, y=name, yend=name))
gg <- gg + geom_text(data=den, color="black", size=4, vjust=0.5, family="",
aes(x=end_year+2, y=name, label=treerings(end_year)))
gg <- gg + geom_text(data=den, color="black", size=4, vjust=0.5, family="",
aes(x=start_year-2, y=name, label=treerings(start_year)))
gg <- gg + geom_text(data=filter(den, sap<=1), color="black", size=4, vjust=0.5, family="",
aes(x=((end_year+start_year)/2), y=name, label=treerings(lengh)))
gg <- gg + geom_text(data=filter(den, sap>=1), color="black", size=4, vjust=0.5, family="",
aes(x=end_year-(sap/2), y=name, label=treerings(sap)))
gg <- gg + geom_text(data=filter(den, sap>=1), color="black", size=4, vjust=0.5, family="",
aes(x=((end_year-sap)/2), y=name, label=treerings(end_year-sap)))
gg <- gg + labs(x="Tree rings", y=NULL, subtitle="innermost ring ↔ outmost ring")
gg <- gg + theme_minimal()
gg <- gg + theme(axis.title.x = element_text(size=10,face='bold'))
gg <- gg + theme(plot.margin=margin(10,10,10,10))
gg <- gg + theme(plot.title=element_text(face="bold"))
gg <- gg + theme(plot.subtitle=element_text(face="bold", size=12, hjust = 0.5, margin=margin(b=2)))
gg <- gg + theme(plot.caption=element_text(size=7, margin=margin(t=12), color="#7a7d7e"))
gg
den <- read.csv("dendro3.csv", stringsAsFactors=FALSE)
arrange(den, no) %>%
mutate(name=factor(name, levels=c(" ", rev(name), " "))) -> den
treerings <- function(x) {
x <- sprintf("%d", round(x))
x
}
# double & triple bars
gg <- ggplot()
gg <- gg + geom_segment(data=den, size=5, color="#D2691E",
aes(x=start_year, xend=end_year, y=name, yend=name))
gg <- gg + geom_segment(data=den, size=5, color="#FFDAB9",
aes(x=end_year-sap, xend=end_year, y=name, yend=name))
gg <- gg + geom_text(data=den, color="black", size=3.5, vjust=0.3, family="",
aes(x=end_year+4, y=name, label=treerings(end_year)))
gg <- gg + geom_text(data=den, color="black", size=3.5, vjust=0.3, family="",
aes(x=start_year-5, y=name, label=treerings(start_year)))
gg <- gg + geom_text(data=filter(den, sap<=1), color="black", size=3.5, vjust=0.3, family="",
aes(x=((end_year+start_year)/2), y=name, label=treerings(lengh)))
gg <- gg + geom_text(data=filter(den, sap>=1), color="black", size=4, vjust=0.3, family="",
aes(x=end_year-(sap/2), y=name, label=treerings(sap)))
gg <- gg + geom_text(data=filter(den, sap>=1), color="black", size=4, vjust=0.3, family="",
aes(x=((end_year-sap)/2), y=name, label=treerings(end_year-sap)))
gg <- gg + geom_text(data=filter(den, mark=="★만재완성"), color="black", size=4, vjust=0.2, family="",
aes(x=end_year+17, y=name, label=mark))
gg <- gg + geom_text(data=filter(den, mark=="☆조재완성"), color="black", size=4, vjust=0.2, family="",
aes(x=end_year+17, y=name, label=mark))
gg <- gg + labs(x="Year", y=NULL, subtitle="innermost ring ↔ outmost ring")
gg <- gg + theme_minimal()
gg <- gg + theme(axis.title.x = element_text(size=10,face='bold'))
gg <- gg + theme(plot.margin=margin(10,50,10,10))
gg <- gg + theme(plot.title=element_text(face="bold"))
gg <- gg + theme(plot.subtitle=element_text(face="bold", size=12, hjust = 0.5, margin=margin(b=2)))
gg <- gg + theme(plot.caption=element_text(size=7, margin=margin(t=12), color="#7a7d7e"))
gg
참고사이트
https://rud.is/b/2016/06/16/your-data-vis-spidey-sense-the-need-for-a-robust-utility-belt/
'연륜연대학 > R Coding' 카테고리의 다른 글
R실습_지도 만들기(2)_마커 (0) | 2022.03.02 |
---|---|
R 실습_능동형 지도 제작 with OSM (0) | 2022.03.02 |
통계의 기본개념 #1, 자료와 변수 개념 (0) | 2020.05.18 |
Hierarchical Clustering using R (0) | 2019.06.20 |
dplR 패키지 설치하기 (0) | 2019.06.20 |