Weitere ähnliche Inhalte
Mehr von Takashi Kitano (14)
可視化周辺の進化がヤヴァイ 〜2016〜
- 6. 主要ライブラリの⽐較
⼤分類 グラフ Plotly rbokeh highcharter
基本グラフ
折れ線グラフ ○ ○ ○
バブルチャート ○ × ?
散布図 ○ ○ ○
ヒートマップ ○ × ○
棒グラフ ○ × ○
⾯グラフ ○ × ○
円グラフ ○ × ○
統計グラフ
ヒストグラム ○ ○ ○
箱ひげ図 ○ ○ ○
- 12. 可視化のサンプルデータ
• 東京都知事選挙候補者3名のTweetデータ
name id created favorite retweet
⼩池百合⼦ 759032551348457472 2016-07-29 23:27:17 184 152
⼩池百合⼦ 759021573537878016 2016-07-29 22:43:39 177 178
⼩池百合⼦ 759021527157252096 2016-07-29 22:43:28 155 171
⼩池百合⼦ 759021455807873024 2016-07-29 22:43:11 144 163
⼩池百合⼦ 759021109580750849 2016-07-29 22:41:49 153 163
⼩池百合⼦ 759013802167848961 2016-07-29 22:12:46 209 194
⼩池百合⼦ 759013745624440832 2016-07-29 22:12:33 211 191
⼩池百合⼦ 759013630452965376 2016-07-29 22:12:05 225 196
⼩池百合⼦ 758959413692538881 2016-07-29 18:36:39 318 208
- 22. ヒートマップ
df %>%
filter(screenName == "ecoyuri") %>%
mutate(date=as.Date(created),
hour=hour(created)) %>%
group_by(date, hour) %>%
summarise(n=n()) %>%
plot_ly(x=hour, y=date, z=n, type="heatmap")
type = “heatmap”を指定
- 32. 円グラフ(1/2)
df %>%
filter(screenName == "ecoyuri") %>%
summarise(favorite = sum(favoriteCount),
retweet = sum(retweetCount)) %>%
plot_ly(labels=colnames(.), values=c(favorite, retweet), type="pie")
labels, values, type=“pie”を指定
- 34. 円グラフ(2/2)
df %>%
filter(screenName == "ecoyuri") %>%
summarise(favorite = sum(favoriteCount),
retweet = sum(retweetCount)) %>%
plot_ly(labels=colnames(.), values=c(favorite, retweet),
type="pie", hole = 0.6)
holeを指定するとドーナツグラフ
- 49. ⾊を変える
df %>%
filter(screenName == "ecoyuri") %>%
mutate(date=as.Date(created),
hour=hour(created)) %>%
group_by(date, hour) %>%
summarise(n=n()) %>%
plot_ly(x=hour, y=date, z=n, type="heatmap", colors="Spectral")
colorsでRColorBrewerの
カラーパレット名を指定する
- 51. 2軸グラフを作る
df %>%
filter(screenName == "ecoyuri") %>%
mutate(date = as.Date(created),
ratio = retweetCount/favoriteCount) %>%
group_by(name, date) %>%
summarise(n=n(), ratio=mean(ratio)) %>%
plot_ly(x=date, y=n, type="bar", name="n") %>%
add_trace(x=date, y=ratio, name="ratio", yaxis="y2") %>%
layout(yaxis2=list(overlaying="y",side="right"))
yaxis2=list(overlaying="y",side="right
")を指定する
- 53. ggplotをインタラクティブに
library(ggplot2)
p <- df %>%
ggplot(aes(x = favoriteCount, y = retweetCount)) +
geom_point(aes(text = paste("Name:", name)), size = 4) +
geom_smooth(aes(colour = name, fill = name)) + facet_wrap(~ name)
ggplotly(p)
ggplotly()でラップするだけ