根据数字列调整冲积图中的线宽
Adjust the width of lines in alluvial chart based on numeric column
我创建了下面的冲积层图表,但没有考虑权重,不知道为什么;所以所有的线都有相同的宽度。我该如何调整?
library(ggalluvial)
library(magrittr)
alpha <- .4
Data<-c("M","M","S","S","G","G")
Report<-c("C","O","C","S","C","O")
Weight<-c(1,1,5,2,2,1)
dr<-data.frame(Data,Report,Weight)
plot_01 <- dr %>%
ggplot(aes(axis1 = Data, axis2 = Report)) +
geom_alluvium(aes(fill = Report, color = Report, weight = Weight),
width = 1/12, alpha = alpha, knot.pos = 0.4) +
geom_stratum(width = 1/6, color = "grey") +
geom_label(stat = "stratum", aes(label = Data)) +
geom_label(stat = "stratum", aes(label = Report)) +
scale_x_continuous(breaks = 1:2, labels = c("Data", "Report")) +
scale_fill_viridis_d() +
scale_color_viridis_d() +
theme_minimal() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 12, face = "bold"))
plot_01
?geom_alluvium
- 我看不到重量美学。你可能是说 y
?
library(ggalluvial)
#> Loading required package: ggplot2
library(magrittr)
alpha <- .4
Data<-c("M","M","S","S","G","G")
Report<-c("C","O","C","S","C","O")
Weight<-c(1,1,5,2,2,1)
dr<-data.frame(Data,Report,Weight)
dr %>%
ggplot(aes(axis1 = Data, axis2 = Report, y = Weight)) +
geom_alluvium(aes(fill = Report, color = Report),
alpha = alpha, knot.pos = 0.4) +
geom_stratum(width = 1/6, color = "grey") +
geom_label(stat = "stratum", aes(label = Data)) +
geom_label(stat = "stratum", aes(label = Report)) +
scale_x_continuous(breaks = 1:2, labels = c("Data", "Report"),
expand = c(0,0)) +
scale_fill_viridis_d() +
scale_color_viridis_d() +
theme_minimal() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 12, face = "bold"))
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning: Removed 2 rows containing missing values (geom_label).
#> Warning: Removed 3 rows containing missing values (geom_label).
由 reprex package (v1.0.0)
于 2021-02-13 创建
我创建了下面的冲积层图表,但没有考虑权重,不知道为什么;所以所有的线都有相同的宽度。我该如何调整?
library(ggalluvial)
library(magrittr)
alpha <- .4
Data<-c("M","M","S","S","G","G")
Report<-c("C","O","C","S","C","O")
Weight<-c(1,1,5,2,2,1)
dr<-data.frame(Data,Report,Weight)
plot_01 <- dr %>%
ggplot(aes(axis1 = Data, axis2 = Report)) +
geom_alluvium(aes(fill = Report, color = Report, weight = Weight),
width = 1/12, alpha = alpha, knot.pos = 0.4) +
geom_stratum(width = 1/6, color = "grey") +
geom_label(stat = "stratum", aes(label = Data)) +
geom_label(stat = "stratum", aes(label = Report)) +
scale_x_continuous(breaks = 1:2, labels = c("Data", "Report")) +
scale_fill_viridis_d() +
scale_color_viridis_d() +
theme_minimal() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 12, face = "bold"))
plot_01
?geom_alluvium
- 我看不到重量美学。你可能是说 y
?
library(ggalluvial)
#> Loading required package: ggplot2
library(magrittr)
alpha <- .4
Data<-c("M","M","S","S","G","G")
Report<-c("C","O","C","S","C","O")
Weight<-c(1,1,5,2,2,1)
dr<-data.frame(Data,Report,Weight)
dr %>%
ggplot(aes(axis1 = Data, axis2 = Report, y = Weight)) +
geom_alluvium(aes(fill = Report, color = Report),
alpha = alpha, knot.pos = 0.4) +
geom_stratum(width = 1/6, color = "grey") +
geom_label(stat = "stratum", aes(label = Data)) +
geom_label(stat = "stratum", aes(label = Report)) +
scale_x_continuous(breaks = 1:2, labels = c("Data", "Report"),
expand = c(0,0)) +
scale_fill_viridis_d() +
scale_color_viridis_d() +
theme_minimal() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 12, face = "bold"))
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.
#> Warning: Removed 2 rows containing missing values (geom_label).
#> Warning: Removed 3 rows containing missing values (geom_label).
由 reprex package (v1.0.0)
于 2021-02-13 创建