<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>R on Dr. Hui Lin</title><link>https://www.huilin.site/tags/r/</link><description>Recent content in R on Dr. Hui Lin</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>linhui@pric.org.cn (Dr. Hui Lin (林辉))</managingEditor><webMaster>linhui@pric.org.cn (Dr. Hui Lin (林辉))</webMaster><copyright>© 2026 Hui Lin. All rights reserved.</copyright><lastBuildDate>Fri, 24 Jul 2026 20:35:00 +0800</lastBuildDate><atom:link href="https://www.huilin.site/tags/r/index.xml" rel="self" type="application/rss+xml"/><item><title>Learning ggmap</title><link>https://www.huilin.site/post/learning-ggmap/</link><pubDate>Fri, 31 Mar 2017 14:24:00 +0000</pubDate><author>linhui@pric.org.cn (Dr. Hui Lin (林辉))</author><guid>https://www.huilin.site/post/learning-ggmap/</guid><description>&lt;p&gt;This is a document for myself to review ggmap package, and how to get quick start.&lt;/p&gt;
&lt;p&gt;ggmap is powerful map plot package in R. Compared with maps package, plots exported from ggmaps are elegant.&lt;/p&gt;
&lt;p&gt;Two steps to plot a map: plot a map raster, decorate the base map with your own data.&lt;/p&gt;

&lt;h3 class="relative group"&gt;Step 1: download your base map
 &lt;div id="step-1-download-your-base-map" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#step-1-download-your-base-map" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;You need to know the location you will plot. Define location in two ways showing below:&lt;/p&gt;</description></item><item><title>Learning ggplot2</title><link>https://www.huilin.site/post/learning-ggplot2/</link><pubDate>Fri, 31 Mar 2017 14:12:00 +0000</pubDate><author>linhui@pric.org.cn (Dr. Hui Lin (林辉))</author><guid>https://www.huilin.site/post/learning-ggplot2/</guid><description>&lt;p&gt;本课程介绍三种R语言的绘图工具包：&lt;code&gt;plot&lt;/code&gt;,&lt;code&gt;qplot&lt;/code&gt;,&lt;code&gt;ggplot&lt;/code&gt;。三种绘图包的能够和语法均不相同。
&lt;code&gt;plot&lt;/code&gt;命令是R语言自带的绘图命令，绘图效果简单，适宜数据分析时绘图。
&lt;code&gt;qplot&lt;/code&gt;命令是R语言初级绘图语言包，能够提供符合出版物标准的简单绘图。得到的图形大方美观。&lt;/p&gt;

&lt;h3 class="relative group"&gt;Lesson: Regression Models Introduction
 &lt;div id="lesson-regression-models-introduction" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#lesson-regression-models-introduction" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;制图：plot(jitter(child,4) ~ parent,galton)&lt;/p&gt;
&lt;p&gt;建立回归函数：使用函数&lt;code&gt;lm&lt;/code&gt;(linear model)，例如：&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;regrline &amp;lt;- lm(child~parent, galton)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;建立回归函数之后，使用&lt;code&gt;abline&lt;/code&gt;(add straight lines to a plot)函数将回归函数在图表中画出，例如&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;abline(regrline, lwd = 3, col = &amp;#34;red&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;#lwd = line width, col = line color&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;画出直线之后可以使用函数&lt;code&gt;summary&lt;/code&gt;查看回归函数的各类参数包括残差， 系数，相关系数等等。&lt;/p&gt;
&lt;hr&gt;

&lt;h3 class="relative group"&gt;qplot
 &lt;div id="qplot" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#qplot" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;qplot&lt;/code&gt; is a basic function in ggplot2 package. It provides some basic plots (e.g. points, smooth, boxplot) for users to learn their database generally.&lt;/p&gt;</description></item><item><title>Learning R in Kaggle</title><link>https://www.huilin.site/post/learning-r-in-kaggle/</link><pubDate>Wed, 22 Mar 2017 12:35:00 +0000</pubDate><author>linhui@pric.org.cn (Dr. Hui Lin (林辉))</author><guid>https://www.huilin.site/post/learning-r-in-kaggle/</guid><description>&lt;p&gt;I&amp;rsquo;m learning data analysis and explore in R following the tutorial posted in &lt;a href="https://www.kaggle.com/mrisdal/titanic/exploring-survival-on-the-titanic" target="_blank" rel="noreferrer"&gt;Kaggle&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here are some sentences I found it useful.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;train &amp;lt;- read.csv('../input/train.csv', stringsAsFactors = F)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This is how to read csv files. Also, use &lt;code&gt;read.delim()&lt;/code&gt;, &lt;code&gt;read.delim2()&lt;/code&gt; to read txt file.&lt;a href="https://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html" target="_blank" rel="noreferrer"&gt;read documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;stringAsFactors&lt;/code&gt; is a useful factor. Here we do not want to use the headers as factors.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;str(dataframe)&lt;/code&gt; use this to check data. Also if you use R Studio, use &lt;code&gt;view(dataframe)&lt;/code&gt; to check data.&lt;/p&gt;</description></item><item><title>Learning R using Swirl</title><link>https://www.huilin.site/post/learning-r-using-swirl/</link><pubDate>Mon, 20 Feb 2017 20:30:00 +0000</pubDate><author>linhui@pric.org.cn (Dr. Hui Lin (林辉))</author><guid>https://www.huilin.site/post/learning-r-using-swirl/</guid><description>&lt;h1 class="relative group"&gt;用Swirl学习R语言，Learn R, in R
 &lt;div id="用swirl学习r语言learn-r-in-r" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#%e7%94%a8swirl%e5%ad%a6%e4%b9%a0r%e8%af%ad%e8%a8%80learn-r-in-r" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h1&gt;
&lt;blockquote&gt;&lt;p&gt;how to import data (read function)
how to manipulate data wit dplyr&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 class="relative group"&gt;lesson: Getting and Cleaning Data
 &lt;div id="lesson-getting-and-cleaning-data" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#lesson-getting-and-cleaning-data" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;我们可以使用&lt;code&gt;read.csv&lt;/code&gt;函数来导入数据。具体查看&lt;code&gt;?read.csv&lt;/code&gt;，例子&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;#set a path to csv file
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;path2csv &amp;lt;-&amp;#34;E:/R-3.3.2/library/swirl/Courses/Getting_and_Cleaning_Data/Manipulating_Data_with_dplyr/2014-07-08.csv&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;#use read.csv to read the csv file
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mydf&amp;lt;-read.csv(path2csv,stringsAsFactors = FALSE)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;#stringsAsFactors: logical: should character vectors be converted to factors?&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;使用&lt;code&gt;dim()&lt;/code&gt;查看数据的行列情况&lt;/p&gt;</description></item><item><title>R basics</title><link>https://www.huilin.site/post/r-basics/</link><pubDate>Sun, 19 Feb 2017 22:23:00 +0000</pubDate><author>linhui@pric.org.cn (Dr. Hui Lin (林辉))</author><guid>https://www.huilin.site/post/r-basics/</guid><description>&lt;h1 class="relative group"&gt;R语言学习笔记
 &lt;div id="r语言学习笔记" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#r%e8%af%ad%e8%a8%80%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h1&gt;
&lt;hr&gt;
&lt;p&gt;这里是关于一些R语言的语法备忘
&lt;a href="https://campus.datacamp.com/" target="_blank" rel="noreferrer"&gt;Learning Website&lt;/a&gt;&lt;/p&gt;

&lt;h3 class="relative group"&gt;Unit 1 Assignment and basic calculation
 &lt;div id="unit-1-assignment-and-basic-calculation" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#unit-1-assignment-and-basic-calculation" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;myapples = 3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;myapples &amp;lt;- 3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;^&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;%%&lt;/code&gt; means the remainder.&lt;/p&gt;
&lt;hr&gt;

&lt;h3 class="relative group"&gt;Unit 2 Vectors
 &lt;div id="unit-2-vectors" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#unit-2-vectors" aria-label="锚点"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;combine function: &lt;code&gt;c()&lt;/code&gt;&lt;/p&gt;</description></item></channel></rss>