---
# System prepended metadata

title: R Language Resources
tags: [R_Lang]

---

###### tags: `R_Lang`

# R Language Resources

## Books
[R for Data Science, Wickham, H. and Grolemund, G.](https://r4ds.had.co.nz/)
[Fundamentals of Quantitative Analysis](https://psyteachr.github.io/quant-fun-v2/index.html)
[APS 240: Data Analysis and Statistics with R](https://dzchilds.github.io/stats-for-bio/)

## IRT Theory

[A Course on Test and Item Analyses](https://www.edmeasurementsurveys.com/index.html) by Margaret Wu, 2022

## Introduction to R

[R for Graduate Students by Y. Wendy Huynh](https://bookdown.org/yih_huynh/Guide-to-R-Book/)
[R for Excel Users by Dr. Julie Stewart Lowndes and Dr. Allison Horst](https://rstudio-conf-2020.github.io/r-for-excel/)

## Data Wrangle

[Create Pivot Tables in R by Chris Bailiss, 2021](https://cran.r-project.org/web/packages/pivottabler/vignettes/v00-vignettes.html)

## Packages 

- Missing values 的處理及視覺化: naniar package
- Data wrangling: dplyr
- IRT 模型: mirt, ggmirt

## Statistics

[ANOVA in R | A Complete Step-by-Step Guide with Examples](https://www.scribbr.com/statistics/anova-in-r/)

[Logistic IRT Models by Julie Wood, 2017](https://quantdev.ssri.psu.edu/sites/qdev/files/IRT_tutorial_FA17_2.html)


## Others 

[RMarkdown for Scientists by Nicholas Tierney](https://rmd4sci.njtierney.com/)
    如何在 R Studio 中撰寫 Markdown 文件，包含圖表的製作。
    
    
    
R FOR JOURNALISTS  https://learn.r-journalism.com/en/

R Cookbook
https://jthomasmock.github.io/nfl_plotting_cookbook/#Boxplots

stringr package cheat sheet
https://evoldyn.gitlab.io/evomics-2018/ref-sheets/R_strings.pdf

RStudio Cheatsheets
https://www.rstudio.com/resources/cheatsheets/

Ggplot2
https://ggplot2-book.org/

Ggplot2 介紹: Always look on the bright side of plots | RStudio
- 介紹 ggplot 的 grammar 的概念
{%youtube izV-qK3nlhA %}

https://www.youtube.com/watch?v=izV-qK3nlhA

R Graphics Cookbook, 2nd edition
https://r-graphics.org/

R 学习 - 图形设置中英字体
https://zhuanlan.zhihu.com/p/32981126

Dplyr 套件說明
https://dplyr.tidyverse.org/

## Keyboard shortcuts
%>%
Cmd + Shift + M (Mac)

<- 
Option + - (Mac)

## Function documenting
Documenting functions by Roxygen skeleton
https://combine-australia.github.io/r-pkg-dev/documenting-functions.html




## Q: sapply 函數做什麼用的？

[取代迴圈的 apply 家族](https://kemushi54.github.io/R-basic/apply_family.html)


## Q: ggplot2 的圖層結構

![](https://englelab.gatech.edu/useRguide/images/dataviz/ge_stats.png)

Source: https://englelab.gatech.edu/useRguide/introduction-to-ggplot2.html#statistics-layer

### Q: 如何在 Histogram 上加入統計數字？

```r=
## https://community.rstudio.com/t/how-to-add-data-labels-to-geom-histogram/87292/3
midterm_plot <- ggplot(score_list_new, aes(x = `midterm(25.0%)`)) +
      geom_histogram(bins = 10, breaks = seq(0, 100, 10), fill="white", color="black") +  
  geom_text(stat="bin", aes(label=..count..), size=4,vjust=-1, breaks = seq(0, 100, 10))

```

重點：

1. 在 geom_histrogram() 及 geom_text 中皆使用相同的 breaks，這樣統計數字才會和圖形高度一致。
2. 在 geom_text() 中指定 stat="bin" 表示在 geom_text 圖層中使用 stat_bin() 轉換函數。
    - 在 aes 中 map label 屬性到 ..count.. stat variable.

More Info: https://ggplot2.tidyverse.org/reference/geom_text.html


## 在 ggplot 內顯示中文

要設定 theme 的字型

```
## theme_set to set the font size base  and font family in the ggplot.
theme.setting <- theme_classic(base_size = 18) + 
  theme(text=element_text(family = "Heiti TC Light")) 
theme_set(theme.setting)
```

