ONLY DO WHAT ONLY YOU CAN DO

こけたら立ちなはれ 立ったら歩きなはれ

ggplot2 で レーダーチャート

ヨーロッパ top 5 league の 2017/2018 シーズンのそれぞれ top 2 team のデータから、レーダーチャートを作ってみた

f:id:fornext1119:20190303142805p:plain

コードは以下の通り

# 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 版

f:id:fornext1119:20190303143231p:plain

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)

とする。

f:id:fornext1119:20190303143512p:plain

これらのグラフが表している情報量は、以下のパラレルチャートと何ら変わりはないが、見た目の楽しさがある。
f:id:fornext1119:20190303154917p:plain


ggplot2によるデータの視覚化

ggplot2によるデータの視覚化