【发布时间】:2021-02-28 23:48:59
【问题描述】:
我有以下情节,我可以在guide 中移动带有label.vjust 的图例标签,但这只会移动标签而不是项目本身。
这是我的情节代码:
b <- ggplot(data = subset(sub.girders.plot, Sample == "CSI"),
aes(x = Girder, y = `Moment LLDF`, fill = factor(S,levels = c("9","12","15")))) + theme_classic() +
geom_boxplot(outlier.shape = NA, position = position_dodge(width = 0.75),
fatten = 1, lwd = 0.2) +
stat_summary(fun = mean, geom="point", shape=23, size=0.5, stroke = 0.2,
position = position_dodge(width = 0.75)) +
stat_boxplot(geom ='errorbar', linetype=1, width=0.5, lwd = 0.2,
position = position_dodge(width = 0.75)) +
geom_point(data = subset(sub.girders.plot, Sample == "Rigid Rotation Method"),
aes(shape = Sample), stroke = 0.3, size = 2,
position = position_dodge(width = 0.75)) +
geom_vline(xintercept = 1.5, col='gray', lwd=0.2) +
geom_vline(xintercept = 2.5, col='gray', lwd=0.2) +
geom_vline(xintercept = 3.5, col='gray', lwd=0.2) +
geom_vline(xintercept = 4.5, col='gray', lwd=0.2) +
annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf, size = 0.35)+
annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf, size = 0.35) +
annotate("segment", x=Inf, xend=Inf, y=-Inf, yend=Inf, size = 0.35) +
scale_shape_manual(values = c(8)) +
labs(x = element_blank(), shape = element_blank(),
fill = "Analytical Data with \n Girder Spacing (ft) of:") +
theme(legend.title.align = 0.5, legend.position = "bottom",
axis.text.y = element_text(size=8, colour="black"),
axis.text.x = element_text(size=8, colour="black", angle=40, vjust=0.6),
axis.title.y = element_text(size=8, colour="black", vjust=0.5, margin = margin(0,4,0,-6)),
axis.line=element_blank(),
axis.ticks = element_line(colour = "black", size = 0.2),
legend.text = element_text(size=8, margin = margin(0,5,0,0)),
legend.title = element_text(size=8, margin = margin(0,2,0,0)),
strip.text.x = element_text(size = 8), axis.ticks.x=element_blank(),
strip.background = element_rect(color = "black", size = 0.4),
legend.spacing.x = unit(0.1, 'cm'), legend.spacing.y = unit(0.1, 'cm'),
legend.background = element_blank(), legend.box.background = element_rect(color = "black", size = 0.2)) +
guides(fill = guide_legend(label.position = "bottom", label.hjust = 0.8, title.vjust = 0.8),
shape = guide_legend(keywidth = unit(3, "mm"),keyheight = unit(3.5, "mm"), label.vjust = -0.5)) +
facet_wrap(vars(UG), ncol = 2)
现在的情节是这样的:
我想对此图表进行两次编辑:
- 向下移动星标。
- 使我的箱线图图例项中的点更小(或从图例项中删除)。目前,当我在
geom_point中增大点大小时,图例中的这个点也会变大。
期望的输出:
编辑
我能够通过以下方式更改箱线图中 fill 中的点:
. . . + guides(fill = guide_legend(label.position = "bottom", label.hjust = 0.8, title.vjust = 0.8,
override.aes = list(shape = c(23))),
shape = guide_legend(keywidth = unit(3, "mm"), keyheight = unit(3, "mm"),
label.vjust = -1))
我仍在寻找一种方法来使用标签将图例项向下移动
【问题讨论】: