-
미국 원자력 발전소 가동 현황 그래프 작성하기R 2018. 10. 19. 10:05
# 미국의 원자력규제위원회
url <- "http://www.nrc.gov/…/r…/PowerReactorStatusForLast365Days.txt"# 데이터 읽어오기
npower <- read.table(url, header = TRUE, sep = "|", stringsAsFactors = FALSE)# 날짜 형태 바꾸기
npower$ReportDt <- as.Date(npower$ReportDt, format = "%m/%d/%Y")# 유일한 목록 보기
unique(npower$Unit)# 데이터 추출하기
some <- npower[npower$Unit == as.character(unique(npower$Unit)[1:12]) , ]# 로케일 설정하기
Sys.setlocale(category = "LC_TIME", locale = "English")# 그래프 작성하기
ggplot(data = some, mapping = aes(x = ReportDt, y = Power)) +
geom_line(col = "red") +
facet_wrap(~Unit, scale = "free_y", nrow = 4) +
scale_x_date(date_labels = "%y-%b", date_breaks = "3 month") +
labs(x = "",
y = "Power",
title = "Nuclear Power Reactor Status over Time",
subtitle = "12 Samples of power reator in US",
caption = "Source : Nuclear Regulatory Commission") +
theme_bw() +
theme(plot.title = element_text(face = "bold"),
strip.background = element_rect(fill = "wheat"),
axis.text = element_text(size = 8, face = "bold"),
legend.title = element_blank())Sys.setlocale()
[출처] 웹스크레이핑과 데이터분석, 곽기영 지음, 도서출판 청람, p23
'R' 카테고리의 다른 글
정규표현식 (0) 2018.10.23 카네기멜론대학교 데이터 (0) 2018.10.19 18. Model Basic with modelr (0) 2018.09.13 여러 개의 sheets 데이터를 하나로 합치기 (0) 2018.09.09 R의 결과를 파워포인트에 작성하기 (0) 2018.09.07