简体   繁体   English

把标签从 plot 下来

[英]Put the labels down from the plot

In a plot like this How is it possible to put the labels of flow down from the plot在这样的plot 怎么可能把流的标签从plot 下来

And mabel the black option more fat and put the labels of these bars now in the middle of the black column next to it并且 mabel 黑色选项更胖,现在将这些条的标签放在它旁边的黑色列的中间

library(ggalluvial)
library(ggplot2)
library(dplyr)

df <- data.frame(status = c("open", "close", "close", "open/close", "close"), 
                 stock = c("google", "amazon", "amazon", "yahoo", "amazon"), 
                 newspaper = c("times", "newyork", "london", "times", "times"))

# Count the number of occurrences for each alluvial
df <- df %>% dplyr::group_by(stock, newspaper, status) %>% 
  summarise(n = n()) 

# Define the factors
df$status <- factor(df$status, levels = c("open", "open/close", "close"))
df$stock <- factor(df$stock, levels = c("google", "amazon", "yahoo"))
df$newspaper <- factor(df$newspaper, levels = c("times", "newyork", "london"))

# Plot the alluvial as in https://cran.r-project.org/web/packages/ggalluvial/vignettes/ggalluvial.html#alluvia-wide-format
ggplot2::ggplot(df.2, aes(y = n, axis1 = stock, axis2 = newspaper)) +
  ggalluvial::geom_alluvium(aes(fill = status), width = 1/12) +
  ggalluvial::geom_stratum(width = 1/12, fill = "black", color = "grey") +
  ggplot2::geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
  ggplot2::scale_x_discrete(limits = c("stock", "newspaper"), expand = c(.05, .05)) +
  ggplot2::scale_fill_brewer(type = "qual", palette = "Set1")

The description of what you want is pretty vague.你想要什么的描述很模糊。 As far as I can tell, you want the legend moved to the bottom of the plot, and the stratum bars made wider:据我所知,您希望将图例移至 plot 的底部,并使地层条变宽:

ggplot(df, aes(y = n, axis1 = stock, axis2 = newspaper)) +
  geom_alluvium(aes(fill = status)) +
  geom_stratum(width = 1/5, fill = "black", color = "grey") +
  geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
  scale_x_discrete(limits = c("stock", "newspaper"), expand = c(.05, .05)) +
  scale_fill_brewer(type = "qual", palette = "Set1") +
  theme_void() +
  theme(legend.position = 'bottom')

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM