ggplot2 で レーダーチャート
ヨーロッパ top 5 league の 2017/2018 シーズンのそれぞれ top 2 team のデータから、レーダーチャートを作ってみた
コードは以下の通り
# Font を準備 windowsFonts(HGKAI=windowsFont("HG正楷書体-PRO")) windowsFonts(COURIER=windowsFont("Courier New")) library("ggplot2") g <- ggplot(d_melt, aes( x = variable, y = value ) ) g <- g + geom_polygon( aes( group=d_melt$"チーム", color=d_melt$"チーム" ), fill = NA ) g <- g + geom_point( aes( group=d_melt$"チーム", color=d_melt$"チーム" ) ) g <- g + theme_bw() g <- g + theme( text=element_text(family="COURIER", size=10), axis.text.x=element_text(family="HGKAI", size=8), axis.ticks.y = element_blank(), axis.text.y = element_blank(), legend.position="bottom" ) g <- g + xlab(NULL) g <- g + ylab(NULL) g <- g + labs(colour=NULL) g <- g + coord_polar() g <- g + guides(color=guide_legend(nrow=2,byrow=TRUE)) plot(g)
facet_wrap 版
facet_wrap を使うと、曲線になってしまう。
これを回避するには、
From Parallel Plot to Radar Plot
の、coord_radar を使用して
# Font を準備 windowsFonts(COURIER=windowsFont("Courier New")) library("ggplot2") g <- ggplot(d_melt, aes( x = variable, y = value ) ) g <- g + geom_polygon( aes( group=d_melt$"チーム", color=d_melt$"チーム" ) ,fill=NA ) g <- g + geom_point( aes( group=d_melt$"チーム", color=d_melt$"チーム" ) ) g <- g + theme_bw() g <- g + theme( text=element_text(family="COURIER", size=10), axis.text.x=element_text(family="HGKAI", size=6), axis.ticks.y = element_blank(), axis.text.y = element_blank(), legend.position="none" ) g <- g + xlab(NULL) g <- g + ylab(NULL) g <- g + labs(colour=NULL) g <- g + coord_radar() g <- g + facet_wrap(~ d_melt$"チーム") plot(g)
とする。
これらのグラフが表している情報量は、以下のパラレルチャートと何ら変わりはないが、見た目の楽しさがある。
- 作者: 山岡直樹
- 発売日: 2018/11/30
- メディア: Kindle版
- この商品を含むブログを見る