DAY 16
2
Big Data

• 折線圖與山形圖
• 長條圖
• 箱型圖
• 小提琴圖
• 散佈圖
• 網路圖

## 折線圖(Line Graph)

ggplot2線圖函式

``````geom_line(mapping = NULL, data = NULL, stat = "identity", position = "identity",
...)
``````

``````#安裝並載入gcookbook
install.packages(c("ggplot2", "gcookbook"))
library(ggplot2)
library(gcookbook)

#製作簡單的資料(女生版1歲前身高曲線97分位)
BaybyGowth <- data.frame(
month = c(1, 2, 4, 6, 8, 10, 12),
height = c(57, 61, 67, 71, 74, 76, 79))
print(BaybyGowth)

#兒童生長曲線
#http://health99.hpa.gov.tw/doc/12024.pdf

#先畫基本線圖
ggplot(BaybyGowth, aes(x = month, y = height)) + geom_line()
``````

## 座標點

``````ggplot(BaybyGowth, aes(x = month, y = height)) + geom_line() + geom_point()
``````

## 調整y軸範圍

``````#(3)加上y軸的上下限
ggplot(BaybyGowth, aes(x = month, y = height)) + geom_line() + geom_point() + ylim(50, max(BaybyGowth\$height))
``````

## 座標顏色

``````#(4)座標加上顏色(darkred)並且用pink色填滿
ggplot(BaybyGowth, aes(x = month, y = height, group = 1)) + geom_line() +
geom_point(size = 4, shape = 22, colour = "darkred", fill = "pink") + ylim(50, max(BaybyGowth\$height))
``````

## 多條折線

(The Effect of Vitamin C on Tooth Growth in Guinea Pigs)

``````#(5)多條折線圖
#載入plyr
library(plyr)
#總結牙齒成長紀錄(60筆彙總成6筆)
tg <- ddply(ToothGrowth, c("supp", "dose"), summarise, length = mean(len))
#檢視整理完成的數據
tg
``````

``````#(6)用給藥方式來畫線(colour)
ggplot(tg, aes(x = dose, y = length, colour = supp)) +
geom_line(linetype = "dashed",size=4) +
geom_point(shape = 22, size = 5, fill = "white")
``````

## stacked Area Graph(山形圖，堆疊區域圖)

1997:世紀帝國一 AOE
2000:世紀帝國二 AOC 征服者入侵

``````#簡單的面積
#(7)製作簡單的世紀帝國資料
AoeStatistics <- data.frame(
民族 = c("法蘭西", "匈奴", "土耳其", "中國", "法蘭西", "匈奴", "土耳其", "中國", "法蘭西", "匈奴", "土耳其", "中國", "法蘭西", "匈奴", "土耳其", "中國"),
分數 = c(25, 25, 25, 25, 30, 20, 20, 30, 40, 10, 40, 10, 30, 0, 20, 50),
紀元 = c(-3000, -3000, -3000, -3000, -1000, -1000, -1000, -1000, 0, 0, 0, 0, 500, 500, 500, 500))

ggplot(AoeStatistics, aes(x = 紀元, y = 分數, fill = 民族)) +
geom_area(colour = "black", size = .2, alpha = .4) +
scale_fill_brewer(palette = "Blues", breaks = rev(levels(AoeStatistics\$民族)))
``````

2014-10 攝於Sevilla,Spain

R語言與機器學習見面會30

### 1 則留言

0
lungrr
iT邦新手 5 級 ‧ 2016-12-23 06:19:38