In RStudio, enter the following line (after the prompt ‘>’) in the Console panel:
hist(rnorm(1000))
Continue with the current session, run the commands below to install the following packages for later use:
# install.packages("pacman")
pacman::p_load(rmarkdown, knitr, here, kableExtra, rmdformats, readxl, tidyverse, xaringan, ERP)
Download the R script file, chem97.R , to a local folder, i.e., directory (say, Documents).
Set the working directory in the current RStudio session by Session -> Set Working Directory -> Choose Directoy
Click on File on the menu to open the script file in the current session.
Compile report from the script (Control_Shift+K) or click on the Notebook icon on the menu.
# histograms and density plots
#
install.packages("mlmRev", repos='https://cloud.r-project.org')
## package 'mlmRev' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Ching-Fang Wu\AppData\Local\Temp\RtmpoztHfg\downloaded_packages
#
library(mlmRev)
#
library(lattice)
#
dta <- Chem97
#
dta$age = dta$age + 18.5
#
histogram(~gcsescore | factor(score), data=dta)
#
tp1 <- histogram(~gcsescore | factor(score), data=dta)
#
tp2 <- densityplot(~ gcsescore,
groups=score,
data=dta,
plot.points=F,
auto.key=list(space="right",title="score"))
# (col.position, row.position, n.col, n.row)
plot(tp1, split=c(1,1,1,2))
# put the second trellis obj at row 2
plot(tp2, split=c(1,2,1,2), newpage=F)
###