在ggplot中覆盖图例符号大小 [英] Overriding legend symbol size in ggplot
本文介绍了在ggplot中覆盖图例符号大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用在本论坛和其他地方找到的命令来覆盖我的符号大小aes.我可以使用Alpha替代功能,但不能使用它的尺寸.
I am trying to override my symbol size aes using commands I have found in this forum and elsewhere. I can get the alpha override to work but not the size.
f1<-ggplot(data=d, aes(x=rpos, y=count, group=id,color=id)) +
geom_point(alpha=0.05, size=0.5) +
scale_fill_manual(values=c("blue", "red")) +
scale_colour_manual(values=c("blue", "red")) +
xlab("Chromosome 1") +
scale_y_continuous(name="Relative coverage",limits=c(-0.5,1.5)) +
guides(colour =guide_legend(override.aes=list(size=5))) +
guides(colour = guide_legend(override.aes = list(alpha = 1))) +
theme_bw()
optns <- theme (
plot.title = element_text(face="bold", size=14),
axis.title.x = element_text(size=12),
axis.title.y = element_text(size=12, angle=90),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position = c(.97,.85),
legend.text = element_text(size=10),
legend.key.size = unit(1, "lines"),
legend.key = element_blank(),
legend.justification = 'right'
)
f1 + ggtitle ("Coverage of Chromosome 1") +
optns + ggsave("Rel.mergedDataChr1.pdf", width = 20, height = 5, dpi = 100)
推荐答案
您的Alpha覆盖覆盖了您的尺寸覆盖.更改此:
Your alpha override is overwriting your size override. Change this:
guides(colour = guide_legend(override.aes = list(size=5))) +
guides(colour = guide_legend(override.aes = list(alpha = 1))) +
对此:
guides(colour = guide_legend(override.aes = list(size=5, alpha = 1))) +
将来,请尝试提供最小工作量示例.这意味着既要提供数据(使其成为一个可行的示例),又要避免像所有您的optns
之类的事情(使它最小化).
In the future, please try to include minimal working examples. This means both providing data (to make it a working example) and also not bothering with things like all your optns
(to keep it minimal).
这篇关于在ggplot中覆盖图例符号大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文