【发布时间】:2022-01-15 09:21:58
【问题描述】:
我正在尝试向我的颜色条图例添加一个垂直居中的标题,但它会将标题堆叠在颜色条的顶部而不是右侧。 我试过添加 position = "right" 但它没有帮助,我试过 vjust,它也不起作用。
它产生的情节:
我想要什么:
代码:
ggplot(df, aes(x=img_type, y=metric),show.legend = FALSE) +
geom_point(aes(size = abs_corr, colour=corr))+scale_size(range =c(-0.1,20) )+
scale_colour_gradient2(
low = "#7e1952",
high = "#2f7a9a",
space = "Lab",
na.value = "white",
guide = "colourbar",
aesthetics = "colour",
mid = "white",
limits=c(-1,1), name = "Spearman's Correlation Coefficient"
)+ guides(size = "none")+
theme(legend.key.height = unit(2.5, "cm"))+
guides(fill = guide_colourbar(label.position = "right"))+
theme(legend.title = element_text(size = 12, angle = 90) )
数据:
metric pval corr img_type abs_corr
1 aes 0.0000 0.6820 T2_TSE 0.6820
2 aes 0.0000 0.7365 T2_FLAIR 0.7365
3 aes 0.0003 0.2412 T1_MPR 0.2412
4 aes 0.0000 0.3510 T1_TIRM 0.3510
5 tg 0.0000 0.4434 T2_TSE 0.4434
6 tg 0.0000 0.8093 T2_FLAIR 0.8093
7 tg 0.0000 0.2813 T1_MPR 0.2813
8 tg 0.0000 0.3513 T1_TIRM 0.3513
9 coent 0.0028 -0.2583 T2_TSE 0.2583
10 coent 0.0008 -0.4210 T2_FLAIR 0.4210
【问题讨论】:
-
这能回答你的问题吗? Legend title position in ggplot2
标签: r ggplot2 legend title colorbar