极坐标/圆形整体布局facet_grid
Polar coordinate / circular layout for the whole facet_grid
我有一个数据集,其中包含 2 个有序离散因子的值,以及一些相应的连续值。 (下面生成随机样本)
randomData = expand.grid(1:5, 1:100) # The two discrete variables
colnames(randomData) = c("index1", "index2")
randomData$z = runif(nrow(randomData)) # The measured value
ggplot(randomData, aes(x = 1, y = z)) +
geom_bar(stat = "identity") +
facet_grid(index1 ~ index2) +
theme_minimal()
我正在尝试使用生成的条形图将整个网格包裹成圆形/极坐标布局,如下所示。
第一个图是所需的输出(由第一个方面图的照片编辑工具操作)。
第二个情节是这个博客的输出 post: http://chrisladroue.com/2012/02/polar-histogram-pretty-and-useful/)。但是,它只包含一个 "row"。
我想不出办法。当我尝试添加 coord_polar()
时,条形图本身受到影响,而不是小平面。
我不认为你可以将面排列成一个圆圈,但你可以通过更改 x 和 y 变量然后使用 coord_polar()
来作弊。
library(ggplot2)
library(dplyr)
d <- rbind(
mutate(randomData, col = "dark"),
mutate(randomData, col = "blank", z = 1 - z)
) %>% arrange(d, index2, index1, col)
ggplot(d, aes(x = factor(index2), y = z)) +
geom_bar(aes(fill = col), stat = "identity", position = "stack") +
scale_fill_manual(values = c(blank = "white", dark = "black")) +
coord_polar() +
theme_minimal() +
guides(fill = FALSE)
您必须对此进行相当多的调整以适合您的原始数据集,但您明白了 - 为值 (1 - z) 添加行并使用它们来堆叠条形图
我有一个数据集,其中包含 2 个有序离散因子的值,以及一些相应的连续值。 (下面生成随机样本)
randomData = expand.grid(1:5, 1:100) # The two discrete variables
colnames(randomData) = c("index1", "index2")
randomData$z = runif(nrow(randomData)) # The measured value
ggplot(randomData, aes(x = 1, y = z)) +
geom_bar(stat = "identity") +
facet_grid(index1 ~ index2) +
theme_minimal()
我正在尝试使用生成的条形图将整个网格包裹成圆形/极坐标布局,如下所示。
第一个图是所需的输出(由第一个方面图的照片编辑工具操作)。 第二个情节是这个博客的输出 post: http://chrisladroue.com/2012/02/polar-histogram-pretty-and-useful/)。但是,它只包含一个 "row"。
我想不出办法。当我尝试添加 coord_polar()
时,条形图本身受到影响,而不是小平面。
我不认为你可以将面排列成一个圆圈,但你可以通过更改 x 和 y 变量然后使用 coord_polar()
来作弊。
library(ggplot2)
library(dplyr)
d <- rbind(
mutate(randomData, col = "dark"),
mutate(randomData, col = "blank", z = 1 - z)
) %>% arrange(d, index2, index1, col)
ggplot(d, aes(x = factor(index2), y = z)) +
geom_bar(aes(fill = col), stat = "identity", position = "stack") +
scale_fill_manual(values = c(blank = "white", dark = "black")) +
coord_polar() +
theme_minimal() +
guides(fill = FALSE)
您必须对此进行相当多的调整以适合您的原始数据集,但您明白了 - 为值 (1 - z) 添加行并使用它们来堆叠条形图