以直线连接数据点的极坐标图也称为雷达图。
Erwan Le Pennec的文章:From Parallel Plot to Radar Plot处理这个问题创建一个与ggplot2
雷达图。
他建议使用定义为coord_radar()
:
coord_radar <- function (theta = "x", start = 0, direction = 1) {
theta <- match.arg(theta, c("x", "y"))
r <- if (theta == "x") "y" else "x"
ggproto("CordRadar", CoordPolar, theta = theta, r = r, start = start,
direction = sign(direction),
is_linear = function(coord) TRUE)
}
有了这个,我们可以创建情节如下:
library(tidyr)
library(dplyr)
library(ggplot2)
iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species)) +
geom_line(size=2) + coord_radar()
coord_radar()
是ggiraphExtra
包的一部分。所以,你可以直接使用它
iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species)) +
geom_line(size=2) + ggiraphExtra:::coord_radar()
注意coord_radar()
不被包导出。所以,需要三重冒号(:::
)来访问该函数。
来源
2017-03-03 06:30:17
Uwe
有[ggradar](http://www.ggplot2-exts.org/ggradar.html),如果这是你想要做的,或者你可以做出必要的曲线与ggforce直线,但一般这是极坐标图表示数据的方式。 – alistaire
嗯。对于连续坐标轴,我同意,但不一定对于这里的部分离散空间。在我看来,ggplot强化了真正应该成为美学选择的东西。 – geotheory
'ggradar'可能有用,但是.. – geotheory