Scatter plot
x = c(1,3,6,9,12,4,7,8,11,10,26)
y = c(1.5,2,7,8,15,5,8,7,11,9,23)
plot(x,y)

#Example 2: Draw a plot, set a bunch of parameters
plot(x,y, xlab="x axis", ylab="y axis", main="TUNGHAN plot", ylim=c(0,20), xlim=c(0,20), pch=15, col="green")
myline.fit<-lm(y ~ x) #fit a line to the points
summary(myline.fit) # get information about the fit
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.6145 -0.9698 -0.3413 0.6124 3.4063
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.95471 0.76146 1.254 0.242
## x 0.88658 0.07013 12.643 4.93e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.474 on 9 degrees of freedom
## Multiple R-squared: 0.9467, Adjusted R-squared: 0.9408
## F-statistic: 159.8 on 1 and 9 DF, p-value: 4.931e-07
abline(myline.fit) # draw the fit line on the plot #畫回歸線
lines(lowess(x,y), col="red") # lowessline (x,y) ##平滑曲線
##xlab="x axis", ylab="y axis" 欄位名稱 ylim=c(0,20), xlim=c(0,20)XY標準大小 pch 點代號 col符號顏色
#Example 3: Add some more points to the graph
x2 = c(0.5, 3, 5, 8, 12)
y2 = c(0.8, 1, 2, 4, 6)
points(x2, y2, pch=16, col="darkgreen")

#Example 4: points and lines overlayed
plot(x2, y2, pch=15, type="o") #type="l" or type="p"

Boxplot
##隨便抽取,建dataframe,取前五列
sex=sample(c("F","M"), 100, replace=TRUE)
race=sample(c("Asia","Europe", "America"), 100, replace=TRUE)
age=sample(c(30:60), 100, replace=T)
data1=data.frame(sex,race,age)
data1[1:5,]
## sex race age
## 1 M America 47
## 2 M America 51
## 3 M Europe 49
## 4 M America 34
## 5 F Asia 54
par(mfrow=c(2,3)) #一個畫面幾張圖 2列3欄可放6張圖
#Box plot
summary(age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 30.00 37.00 46.50 45.36 53.00 60.00
par( mfrow=c(2,2))
boxplot(age, main="age")
boxplot( age~race, main="Age by Race", col="Gray", boxwex=0.3)
boxplot( age~sex*race, main="Age by Race", col=(c("gold","darkgreen")))
boxplot( age~sex*race, las = 2) #To draw the names vertically, instead of horizontally.

# las=0, 1, 2, 3