在冲积层中进行的类似可视化
A similar Visulization which is done in Alluvial
我遇到过这种可视化,我正在尝试制作类似的。
这是图片!
它看起来像一个 sankey(当然没有流程)所以我尝试用类似的结果做一个 sankey,但我最终没有类似的东西。我也试过用 Alluvial 来做,但我最终得到了不同的图表。
任何人都可以向我解释什么是特殊的可视化,如何做到这一点。
我试着用 Alluvial 做,但我得到了不同的图表。
这是我用冲积层得到的。数据与上面显示的示例不同。
数据:
df <- data.frame(Caste = c("SC","ST","OBC","FC"),
Total_population = c(0.17, 0.09, 0.52, 0.22),
Convicts = c(0.209, 0.137, 0.312, 0.341))
冲积层代码:
ggplot(df,aes(y = Freq, axis1 = Details, axis2 = Caste)) +
geom_alluvium(fill = cols ,width = 1/12) +
geom_stratum(width = 1/12, fill = mycols, color = "grey") +
geom_label(stat = "stratum", infer.label = TRUE) +
scale_x_discrete(limits = c("Details", "Caste"), expand =c(.05,.05))+
scale_fill_brewer(type = "qual", palette = "Set1") +
ggtitle("Convict rate with total population")
这是我得到的冲积层
.
这不是我想要的。
我需要知道的事情,
- 如何制作此可视化的精确版本。
- 如何仅使用我拥有的数据的结果,而不是整个数据 table。
谢谢
这应该让你开始:
library(ggalluvial)
library(forcats)
library(tidyr)
library(dplyr)
library(scales)
df1 <-
df %>%
pivot_longer(-Caste)
ggplot(data = df1, aes(y = value, x = fct_rev(name), stratum = Caste, alluvium = Caste, fill = Caste)) +
geom_flow(width = 1/5, colour = "black")+
geom_stratum(width = 1/5)+
geom_text(data = filter(df1, name == "Total_population"), stat = "stratum", infer.label = TRUE, size = 5, nudge_x = -0.2) +
geom_text(aes(label = percent(value)), stat = "stratum", size = 5, colour = "white") +
annotate(geom = "text", x = 0.7, y = 0.5, label = "Total population", size = 7)+
annotate(geom = "text", x = 2.2, y = 0.5, label = "Convicts", size = 7)+
coord_flip() +
labs(title = "Convict rate with total population",
x = NULL,
y = NULL)+
theme(legend.position = "none",
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.background = element_blank())
数据
df <- data.frame(Caste = c("SC","ST","OBC","FC"),
Total_population = c(0.17, 0.09, 0.52, 0.22),
Convicts = c(0.209, 0.137, 0.312, 0.341))
由 reprex package (v0.3.0)
于 2020-07-11 创建
这只是为了好玩 - 我已经采纳了 Peter 的回答(他值得完全信任并且应该被授予接受的答案)并进行了一些修改以使其更像问题中的示例:
代码
library(ggalluvial)
library(forcats)
library(tidyr)
library(scales)
dfl < pivot_longer(df, -Caste)
ggplot(data = dfl, aes(y = value, x = fct_rev(name),
stratum = Caste, alluvium = Caste, fill = Caste)) +
geom_flow(colour = "black", size = 3, linetype = 1, alpha = 1)+
geom_flow(fill = "black", size = 3, linetype = 1, alpha = 0.5)+
geom_stratum(colour = "black", size = 3)+
geom_text(stat = "stratum", infer.label = TRUE, size = 5,
nudge_x = -0.2, aes(alpha = fct_rev(name)), color = "white") +
geom_text(aes(label = percent(value)), stat = "stratum", size = 5, color = "white") +
annotate(geom = "text", x = 0.7, y = 0.5, label = "Total population",
size = 10, color = "white") +
annotate(geom = "text", x = 2.3, y = 0.5, label = "Convicts",
size = 10, color = "white") +
coord_flip() +
scale_alpha_manual(values = c(1, 0)) +
scale_fill_manual(values = rev(c("#bbbacc", "#9d9caa", "#767583", "#585865", "#40404a"))) +
labs(title = "Convict rate with total population",
x = NULL,
y = NULL)+
theme_void() +
theme(legend.position = "none",
plot.background = element_rect(fill = "black"),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.background = element_blank(),
panel.spacing = margin(0, 0, 0, 0))
我遇到过这种可视化,我正在尝试制作类似的。
这是图片!
它看起来像一个 sankey(当然没有流程)所以我尝试用类似的结果做一个 sankey,但我最终没有类似的东西。我也试过用 Alluvial 来做,但我最终得到了不同的图表。 任何人都可以向我解释什么是特殊的可视化,如何做到这一点。
我试着用 Alluvial 做,但我得到了不同的图表。
这是我用冲积层得到的。数据与上面显示的示例不同。
数据:
df <- data.frame(Caste = c("SC","ST","OBC","FC"),
Total_population = c(0.17, 0.09, 0.52, 0.22),
Convicts = c(0.209, 0.137, 0.312, 0.341))
冲积层代码:
ggplot(df,aes(y = Freq, axis1 = Details, axis2 = Caste)) +
geom_alluvium(fill = cols ,width = 1/12) +
geom_stratum(width = 1/12, fill = mycols, color = "grey") +
geom_label(stat = "stratum", infer.label = TRUE) +
scale_x_discrete(limits = c("Details", "Caste"), expand =c(.05,.05))+
scale_fill_brewer(type = "qual", palette = "Set1") +
ggtitle("Convict rate with total population")
这是我得到的冲积层
这不是我想要的。
我需要知道的事情,
- 如何制作此可视化的精确版本。
- 如何仅使用我拥有的数据的结果,而不是整个数据 table。
谢谢
这应该让你开始:
library(ggalluvial)
library(forcats)
library(tidyr)
library(dplyr)
library(scales)
df1 <-
df %>%
pivot_longer(-Caste)
ggplot(data = df1, aes(y = value, x = fct_rev(name), stratum = Caste, alluvium = Caste, fill = Caste)) +
geom_flow(width = 1/5, colour = "black")+
geom_stratum(width = 1/5)+
geom_text(data = filter(df1, name == "Total_population"), stat = "stratum", infer.label = TRUE, size = 5, nudge_x = -0.2) +
geom_text(aes(label = percent(value)), stat = "stratum", size = 5, colour = "white") +
annotate(geom = "text", x = 0.7, y = 0.5, label = "Total population", size = 7)+
annotate(geom = "text", x = 2.2, y = 0.5, label = "Convicts", size = 7)+
coord_flip() +
labs(title = "Convict rate with total population",
x = NULL,
y = NULL)+
theme(legend.position = "none",
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.background = element_blank())
数据
df <- data.frame(Caste = c("SC","ST","OBC","FC"),
Total_population = c(0.17, 0.09, 0.52, 0.22),
Convicts = c(0.209, 0.137, 0.312, 0.341))
由 reprex package (v0.3.0)
于 2020-07-11 创建这只是为了好玩 - 我已经采纳了 Peter 的回答(他值得完全信任并且应该被授予接受的答案)并进行了一些修改以使其更像问题中的示例:
代码
library(ggalluvial)
library(forcats)
library(tidyr)
library(scales)
dfl < pivot_longer(df, -Caste)
ggplot(data = dfl, aes(y = value, x = fct_rev(name),
stratum = Caste, alluvium = Caste, fill = Caste)) +
geom_flow(colour = "black", size = 3, linetype = 1, alpha = 1)+
geom_flow(fill = "black", size = 3, linetype = 1, alpha = 0.5)+
geom_stratum(colour = "black", size = 3)+
geom_text(stat = "stratum", infer.label = TRUE, size = 5,
nudge_x = -0.2, aes(alpha = fct_rev(name)), color = "white") +
geom_text(aes(label = percent(value)), stat = "stratum", size = 5, color = "white") +
annotate(geom = "text", x = 0.7, y = 0.5, label = "Total population",
size = 10, color = "white") +
annotate(geom = "text", x = 2.3, y = 0.5, label = "Convicts",
size = 10, color = "white") +
coord_flip() +
scale_alpha_manual(values = c(1, 0)) +
scale_fill_manual(values = rev(c("#bbbacc", "#9d9caa", "#767583", "#585865", "#40404a"))) +
labs(title = "Convict rate with total population",
x = NULL,
y = NULL)+
theme_void() +
theme(legend.position = "none",
plot.background = element_rect(fill = "black"),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.background = element_blank(),
panel.spacing = margin(0, 0, 0, 0))