我想将出现在右侧y轴上的面标签添加到不是面的ggplot。有没有一个简单的方法来做到这一点?Plotv2显示了我想要添加的y轴标签,但实际上我并不想将数据拆分到两个方面。是否有设置的主题参数,可以用来添加第二个y轴标题容易,或者我必须去使用自定义grob?
library(ggplot2)
library(grid)
df <- data.frame(
Position=(c(1:5000)),
Signal=(c((rep(c(5),times=2000)), (rep(c(100),times=1000)), (rep(c(5),times=2000))))
)
Plotv1 <- ggplot() +
geom_line(data = df, aes(x=Position, y=Signal, col = "#000000")) +
coord_cartesian(clip="off") +
guides(fill = "none") +
guides(color=guide_legend(title="MyLegend")) +
theme_bw() +
theme(axis.text.x = element_blank()) +
theme(
axis.title.x = element_text(margin=margin(t=30)),
legend.title = element_text(colour = "#000000", size=12),
legend.text = element_text(colour = "#000000", size=12)
) +
annotation_custom(
grid::segmentsGrob(
y0 = unit(-25, "pt"),
y1 = unit(-25, "pt"),
arrow = arrow(angle=45, type="closed", length=unit(.15, 'cm')),
gp = grid::gpar(lwd=3, col="#000000", fill="#000000")
),
xmin = 2000,
xmax = 3000
)
ggsave(paste("~/Desktop/Plotv1.png", sep = ""), Plotv1, width = 8, height = 1.7)
Plotv2 <- Plotv1 +
facet_grid(Signal~.)
ggsave(paste("~/Desktop/Plotv2.png", sep = ""), Plotv2, width = 8, height = 1.7)
1条答案
按热度按时间s71maibg1#
您可以考虑添加一个冗余的facet标签,或者使用辅助轴在右侧添加其他标题: