table of Contents
Jupyter notebook uses R examples
To configure IRkernel in jupyter notebook under windows, see:
Fun with Jupyter Notebook5-configure python|R|Julia|Stata
The premise is that R has been installed
first step
Done in R
options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))
install.packages('IRkernel',dependencies=TRUE)
Error:
tar: Failed to set default locale
solve:
system('defaults write org.R-project.R force.LANG en_US.UTF-8')
Reference: https://stackmirror.com/page/3xysh3tfepl
Second step
Done in R
IRkernel::installspec(user = FALSE)
报错:
Error in IRkernel::installspec(user = FALSE) :
jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.
In addition: Warning message:
In system2("jupyter", c("kernelspec", "--version"), FALSE, FALSE) :
error in running command
solve:
Done in R
R.home()
/Library/Frameworks/R.framework/Resources/
Add bin/R
Terminal completed
>/Library/Frameworks/R.framework/Resources/bin/R
IRkernel::installspec(user = FALSE)#To install system-wide, set user to False in the installspec command:
Error:
[Errno 13] Permission denied: '/usr/local/share/jupyter'
Perhaps you want to install with `sudo` or `--user`?
solve:
Direct root installation, perfect solution
Terminal completed
>sudo /Library/Frameworks/R.framework/Resources/bin/R
Done in R
options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))#设置镜像源
install.packages('IRkernel',dependencies=TRUE)
试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/macosx/contrib/4.0/IRkernel_1.1.1.tgz'
Content type 'application/octet-stream' length 221094 bytes (215 KB)
==================================================
downloaded 215 KB
The downloaded binary package is in /tmp/RtmpAqkmDv/downloaded_packages
IRkernel::installspec(user = FALSE)#To install system-wide, set user to False in the installspec command:
[InstallKernelSpec] Installed kernelspec ir in /usr/local/share/jupyter/kernels/ir
Exit R and click on jupyter notebook
Perfect solution.
Jupyter notebook uses R examples
library(RColorBrewer) # 用分类调色板
par(mfrow = c(2, 1), mar = c(3, 2.5, 0.5, 0.1))
death <- t(VADeaths)[, 5:1]
barplot(death, col = brewer.pal(4, "Set1"))
barplot(death,
col = brewer.pal(4, "Set1"), beside = TRUE,
legend.text = TRUE
)
Reference
"Modern Statistical Graphics"