【发布时间】:2017-09-24 23:17:53
【问题描述】:
我想在ggplot 的绘图区域之外添加一个包含 10 条单独堆叠行的文本框。我的文字是:t = c("a=1", "b=2", "c=3", ... , "j=10"),但这些标签独立于我制作的原始ggplot 的data.frame。如何在绘图区域之外添加 10 行?
例如,我想在下图右侧的向量t 周围添加一个文本框:
df = data.frame(y=rnorm(300), test=rep(c(1,2,3),each=100))
t = c("a=1", "b=2", "c=3", "d=4", "e=5", "f=6", "g=7", "h=8", "i=0", "j=10")
p <- ggplot(df, aes(x=factor(test), y=y))
p <- p + geom_violin() + geom_jitter(height=0, width=0.1)
p <- p + theme(legend.title=element_blank(), plot.margin=unit(c(0.1, 3, 0.1, 0.1), "cm"))
p
【问题讨论】:
-
请提供可重现的示例,以便我们提供针对您的问题量身定制的代码。