This is a document for myself to review ggmap package, and how to get quick start.
ggmap is powerful map plot package in R. Compared with maps package, plots exported from ggmaps are elegant.
Two steps to plot a map: plot a map raster, decorate the base map with your own data.
Step 1: download your base map # You need to know the location you will plot. Define location in two ways showing below:
本课程介绍三种R语言的绘图工具包:plot,qplot,ggplot。三种绘图包的能够和语法均不相同。 plot命令是R语言自带的绘图命令,绘图效果简单,适宜数据分析时绘图。 qplot命令是R语言初级绘图语言包,能够提供符合出版物标准的简单绘图。得到的图形大方美观。
Lesson: Regression Models Introduction # 制图:plot(jitter(child,4) ~ parent,galton)
建立回归函数:使用函数lm(linear model),例如:
regrline <- lm(child~parent, galton) 建立回归函数之后,使用abline(add straight lines to a plot)函数将回归函数在图表中画出,例如
abline(regrline, lwd = 3, col = "red") #lwd = line width, col = line color 画出直线之后可以使用函数summary查看回归函数的各类参数包括残差, 系数,相关系数等等。
qplot # qplot is a basic function in ggplot2 package. It provides some basic plots (e.g. points, smooth, boxplot) for users to learn their database generally.
I’m learning data analysis and explore in R following the tutorial posted in Kaggle
Here are some sentences I found it useful.
train <- read.csv('../input/train.csv', stringsAsFactors = F)
This is how to read csv files. Also, use read.delim(), read.delim2() to read txt file.read documentation
stringAsFactors is a useful factor. Here we do not want to use the headers as factors.
str(dataframe) use this to check data. Also if you use R Studio, use view(dataframe) to check data.
用Swirl学习R语言,Learn R, in R # how to import data (read function) how to manipulate data wit dplyr
lesson: Getting and Cleaning Data # 我们可以使用read.csv函数来导入数据。具体查看?read.csv,例子
#set a path to csv file path2csv <-"E:/R-3.3.2/library/swirl/Courses/Getting_and_Cleaning_Data/Manipulating_Data_with_dplyr/2014-07-08.csv" #use read.csv to read the csv file mydf<-read.csv(path2csv,stringsAsFactors = FALSE) #stringsAsFactors: logical: should character vectors be converted to factors? 使用dim()查看数据的行列情况