我正在使用以下代码在中生成一个简单的箱形图ggplot2
:
# Libs data
data("mtcars"); require(ggplot2); require(ggthemes)
# Chart
ggplot(data = mtcars) +
geom_boxplot(aes(y = wt, x = as.factor(am)),
fill = "gray87") +
xlab("AM") +
ylab("WT") +
theme_gdocs() +
ggtitle("WT by AM") +
theme(axis.title.y = element_text(angle = 90),
axis.ticks = element_line(colour = "black", linetype = "solid",
size = 0.5),
panel.grid = element_line(colour = "gray"))
我想在图表中添加字幕,并对其呈现方式进行一些控制。我正在关注此讨论并使用代码:
# Chart
ggplot(data = mtcars) +
geom_boxplot(aes(y = wt, x = as.factor(am)),
fill = "gray87") +
xlab("AM") +
ylab("WT") +
theme_gdocs() +
ggtitle(expression(atop("WT by AM",
atop(italic("Some crucial note that has to be here"), "")))) +
theme(axis.title.y = element_text(angle = 90),
axis.ticks = element_line(colour = "black", linetype = "solid",
size = 0.5),
panel.grid = element_line(colour = "gray"))
这看起来真的很糟糕,我想更改一些内容:
我尝试了其他事情,例如下面的代码:
ggplot(data = mtcars) +
geom_boxplot(aes(y = wt, x = as.factor(am)),
fill = "gray87") +
xlab("AM") +
ylab("WT") +
theme_gdocs() +
ggtitle(expression(atop("WT by AM",
atop(italic("Stupid note"), "")))) +
theme(axis.title.y = element_text(angle = 90),
axis.ticks = element_line(colour = "black", linetype = "solid",
size = 0.5),
panel.grid = element_line(colour = "gray"),
plot.title = element_text(size = 16, colour = "black", hjust = -1))
但它完全隐藏了标题:
在“这很愚蠢,但可以使用”文件中,您可以在中心右侧添加空格以强制向左对齐。可以使用数学确定正确的空格数,但是我看不到如何将字符串变量传递回atop
。
# Chart
ggplot(data = mtcars) +
geom_boxplot(aes(y = wt, x = as.factor(am)), fill = "gray87") +
xlab("AM") + ylab("WT") + theme_gdocs() +
ggtitle(expression(atop("WT by AM ",
atop(italic("Some crucial note that has to be here"), "")))) +
theme(axis.title.y = element_text(angle = 90),
axis.ticks = element_line(colour = "black", linetype = "solid", size = 0.5),
panel.grid = element_line(colour = "gray"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句