George Chao
- 清大統計所畢業
- 資料分析相關產品顧問
- 巨量資料分析平台、視覺化、資料庫
- Taiwan R User Group 工作人員

Wush Wu, Johnson Hsieh, George Chao




A convenient tool to generate reproducible document.
document 、 slidesmathjax.rmdintegrated shinycode and texthtmlKnit Buttoninstall.packages("rmarkdown")


$ equation $$$ equation $$
rmarkdown::render("input.Rmd")
在RStudio中,在UI界面中點選help (?)可以查閱Markdown語法

R code will be evaluated and printed
```{r}
summary(cars$dist)
```
summary(cars$dist)
Min. 1st Qu. Median Mean 3rd Qu. Max.
2.00 26.00 36.00 42.98 56.00 120.00
```{r plot}
summary(cars)
plot(cars)
```
Easy Navigation in RStudio

echo(TRUE): whether to include R source code in the output fileeval(TRUE): whether to evaluate the code chunkmessage(TRUE): whether to preserve messages emitted by message()include(TRUE): whether to be written into the output document, but the code is still evaluated and plot files are generatedwarning(TRUE): whether to preserve warnings in the output comment("##"): set to comment notation results('hide','asis'): hide output ; asis treats the output of your R code as literal Markdown (when using like kable function)Set global chunk options at code chunks header:
knitr::opts_chunk$set(echo=FALSE, results='hide')
利用R Markdown 製作《一周天氣預報》書面報告。
利用R Markdown 製作《一周天氣預報》書面報告。
# Hint:
# 1. 下載weather-utf8.csv到自己的電腦上
# 2. 在R chunk中,利用read.csv()讀取檔案進行分析
# Windows: read.csv(,fileEncoding="UTF-8")
# 3. 找出01/28當日最高溫 max()
# 4. 找出01/28當日最低溫 min()
# 5. use inline R chunk `r max(...)`
利用R Markdown 製作《一周天氣預報》書面報告。
# Hint for Linu& Mac:
dat <- read.csv("weather-utf8.csv")
max(dat[1:2, 4:5])
min(dat[1:2, 4:5])
# 預測高溫約`r max(dat[1:2,4:5])`度,低溫約`r min(dat[1:2,4:5])`度
# Hint for Windows:
dat <- read.csv("data/weather-utf8.csv",fileEncoding="UTF-8")
max(dat[1:2, 4:5])
min(dat[1:2, 4:5])
# 預測高溫約`r max(dat[1:2,4:5])`度,低溫約`r min(dat[1:2,4:5])`度
Set results='asis' to write raw results from R into the output document
knitr::kable
```{r, results='asis'}
knitr::kable(women)
```
| height | weight |
|---|---|
| 58 | 115 |
| 59 | 117 |
| 60 | 120 |
| 61 | 123 |
| 62 | 126 |
| 63 | 129 |
利用R Markdown 製作《一周天氣預報》書面報告。
# Hint:
# 你可能需要dplyr套件
# 可以先用filter把白天、晚上分開處理
# 利用 paste(低溫,高溫,sep="-") 來製作溫度區間, i.e. 16-17
# 利用colnames, rownames來對整理好的資料表的行與列命名
利用R Markdown 製作《一周天氣預報》書面報告。
library(dplyr)
day1 <- filter(dat, 早晚=="白天")
day2 <- mutate(day1, 溫度=paste(高溫,低溫,sep="-"))
day3 <- select(day2, 天氣, 溫度)
night1 <- filter(dat, 早晚=="晚上")
night2 <- mutate(night1, 溫度=paste(高溫,低溫,sep="-"))
night3 <- select(night2, 天氣, 溫度)
out <- data.frame(t(bind_cols(day3, night3)))
colnames(out) <- day1$日期
rownames(out) <- c("白天天氣","白天溫度","晚上天氣","晚上溫度")
利用R Markdown 製作《一周天氣預報》書面報告。
```{r results='asis', echo=FALSE}
knitr::kable(out)
```
利用R Markdown 製作《一周天氣預報》書面報告。
# Hint:
# 你可能需要ggplot2套件
# Mac顯示中文需設置字型
# http://equation85.github.io/blog/graph-font-of-r-in-mac-os-x/
# par(family='STHeiti')
利用R Markdown 製作《一周天氣預報》書面報告。
library(ggplot2);library(reshape2)
dat1 <- mutate(dat, 時間=paste(日期,早晚,sep="\n"))
dat2 <- select(dat1, 時間, 高溫, 低溫)
colnames(dat2)[1] <- "時間" # for Windows user
dat3 <- melt(dat2)
g <- ggplot(dat3, aes(x=時間, y=value, group=variable, colour=variable)) +
geom_line() +
labs(x="時間", y="溫度")
# 顯示中文字 Mac user only
g + theme_gray(base_family="STHeiti")
利用R Markdown 製作《一周天氣預報》書面報告。
You can add R Markdown and HTML in the YAML content.
---
title: "Introduction to R Markdown"
author: "Wush Wu, Johnson Hsieh, George Chao"
date: "2015-04-12"
output: html_document
---
It’s possible to embed a Shiny application within a document.
