英文:
Vertical adjustment of symbols relative to text in legend
问题
关于您的问题,您希望将图例中的符号与相应文本的第一行垂直对齐。这可以通过使用\n
来实现。您可以将long\ntext
更改为long
,以确保符号与标签的第一行对齐。
plot(table(iris$species))
legend('right', c('A', 'B', 'long'), fill = colors(3))
这样,符号将与标签的第一行(即long
)垂直对齐。
英文:
Is there a way to vertical align the symbols in a legend relative to the first line of the corresponding text?
plot(table(iris$species))
legend('right',c('A','B','long\ntext'), fill = colors(3))
The labels A
and B
are vertically aligned to the corresponding symbols, but the symbol corresponding to the the third label (long text
with a line-break between the words) is aligned to the middle of this label.
I would prefer if the symbol would be aligned to the first line of the label (i.e. long
).
答案1
得分: 2
以下是已翻译的代码部分,不包括问题的答案:
在文本之前放一个空行是最简单的方法。这样,文本的第一行将与框对齐:
英文:
The easiest way is to put a blank line before the text. That way, the first line of text will be aligned with the box:
pie(table(iris$Species), col = palette.colors(3, "Pastel 1"), cex = 2)
legend('right',c('A','B',' \nlong\ntext'), fill = palette.colors(3, "Pastel 1"),
cex = 2, box.lty = 0, y.intersp = 0)
答案2
得分: 0
iris <- iris
ggplot(iris, aes(x=Species, fill=Species)) +
geom_bar() +
scale_fill_manual(values=colors(3), labels=c('A', 'B', '长文本')) +
theme(legend.position="右侧", legend.justification=0.5)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论