1

hist(rnorm(1000))

2

#install.packages("pacman")
pacman::p_load(rmarkdown, knitr, here, kableExtra, rmdformats, readxl, tidyverse, xaringan, ERP)

3

#install.packages("mlmRev", repos='https://cloud.r-project.org')

#
library(mlmRev)
library(lattice)

we can suppress unwanted messages or warnings in output by modifying chunk option. {r message=FALSE, warning=FALSE}

more informatiton: https://yihui.org/knitr/options/

# read the data
dta <- Chem97

# age plus 18.5
dta$age = dta$age + 18.5

# histogram
histogram(~gcsescore | factor(score), data=dta)

# Put the histogram into tp1
tp1 <- histogram(~gcsescore | factor(score), data=dta)

# Put the densityplot into tp2
tp2 <- densityplot(~ gcsescore, 
                   groups=score, 
                   data=dta, 
                   plot.points=F, 
                   auto.key=list(space="right",title="score"))

histogram改變圖的位置與長寬

改變擺放位置左/右,改變擺放位置上/下, 縮寬, 縮高

#col.position,row.position, n.col, n.row
plot(tp1, split=c(1,1,1,2))

densityplot改變圖的位置與長寬

改變擺放位置/下,縮高

# put the second trellis obj at row 2
plot(tp2, split=c(1,2,1,2), newpage=T)