R中的积云积图的标签和主题 [英] Labelling and theme of ggalluvial plot in R
本文介绍了R中的积云积图的标签和主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在过去的几个小时里,我试图理解围绕 ggalluvial 的整个设计/主题/标签概念,但是我失败了. 几分钟之内,我就能够生成所需的图形(由于使用了ggalluvial软件包),但是我无法弄清楚如何生成想要的正确标签/主题.
For the past hours I have tried to understand the whole design/theme/labelling concept around ggalluvial, but I failed. Within minutes I was able to produce the kind of graph I want (thanks to the package ggalluvial), but I can't figure how to produce the correct labelling/theme I'd like to have.
这是我目前所在的位置:
This is where I am currently:
这是我最初的位置:
This is where I was initially:
为了让您了解我在哪里,这是一个可复制的示例
To get you to understand where I am, here's a reproducible example
我使用了以下代码:
library(ggalluvial)
ds <- as.data.frame(Titanic)
ggplot(ds,
aes(weight = Freq, axis1 = Sex, axis2 = Class)) +
geom_alluvium(aes(fill = Sex), width = 1/12) +
geom_stratum(width = 1/4, fill = "black", color = "grey") +
scale_x_continuous(breaks = 1:2, labels = c("Sex", "Class")) +
scale_fill_manual(name = "", values=c("#A0A0A0", "#494949")) +
ggtitle("Titanic Survival") +
theme_bw() +
geom_text(stat = "stratum", color="white",label.strata = TRUE,
angle=c(90,90,0,0,0,0) , size=6,
nudge_y=c(1,2,3,4,5,0)) +
theme(legend.position = "bottom",
title = element_text(size = 20),
legend.text = element_text(size = 20),
axis.text.y = element_blank(),
axis.text.x = element_text(size=20))
我想更改的内容:
- 垂直向左旋转标签
- 完成
- turn labels on the left vertically
- done
- 我尝试过轻推.但是将这些图例放在图外可能更有用,例如像在轴上一样?
- 完成
- 圆顶
我很高兴为此提供任何帮助.谢谢.
I am very happy for any help on this. Thank you.
推荐答案
您可以尝试:
ggplot(ds, aes(weight = Freq, axis1 = Sex, axis2 = Class)) + geom_alluvium(aes(fill = Sex), width = 1/12) + geom_stratum(width = 1/16, fill = "black", color = "grey") + scale_x_continuous(breaks = 1:2, labels = c("Sex", "Class")) + scale_fill_manual(name = "", values=c("#A0A0A0", "#494949")) + ggtitle("Titanic Survival") + theme_bw() + geom_text(stat = "stratum", color="red",label.strata = TRUE, angle=c(0,0,45,45,45,45),size=5) + theme(legend.position = "bottom", title = element_text(size = 20), legend.text = element_text(size = 20), axis.text.y = element_blank(), axis.text.x = element_text(size=20))
- 添加具有与
angle=c(0,0,45,45,45,45)
相同的标签长度的向量
- 在
theme()
中添加 - 待处理
- 通过
theme
进行尺寸- 通过
theme()
(例如x轴标签)
通过
geom_text()
中的size=5
中的 - 通过
- 文本中的文本
axis.text.y = element_blank()
- add a vector with the same length of labels like
angle=c(0,0,45,45,45,45)
- add
axis.text.y = element_blank()
intheme()
- pending
- Sizes via
theme
- via
theme()
such as x-axis labels - text in plot via
size=5
ingeom_text()
这篇关于R中的积云积图的标签和主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- via
查看全文