ggplot:由geom_text打印的文本不清楚 [英] ggplot: text printed by geom_text is not clear
本文介绍了ggplot:由geom_text打印的文本不清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用geom_text打印的文本不是很清楚.如何使它更清楚?
The text printed using geom_text is not very clear. How can I make it more clear?
data = data.frame(rnorm(1000))
colnames(data) = "numOfX"
m <- ggplot(data, aes(x=numOfX))
m + geom_histogram(colour = "blue", fill = "white", binwidth = 0.5) +
annotate("segment", x=10,xend=10,y=20,yend=0,arrow=arrow(), color="blue") +
geom_text(aes(10, 30, label="Observed \n value"), color = "blue")
推荐答案
对文本以及箭头使用annotate
:
m + geom_histogram(colour = "blue", fill = "white", binwidth = 0.5) +
annotate("segment", x=10,xend=10,y=20,yend=0,arrow=arrow(), color="blue") +
annotate("text", x=10, y=30, label="Observed \n value", color = "blue")
原因是geom_text
为数据帧中的每一行数据覆盖文本,而annotate
仅将文本绘制一次.正是这种过度绘图导致了粗体的像素化文本.
The reason is that geom_text
overplots the text for each row of data in the data frame, whereas annotate
plots the text only once. It is this overplotting that causes the bold, pixellated text.
我确定这个问题最近得到了回答.我将尝试查找参考:
最近有人问了类似的问题:
I am sure this question was answered recently. I'll try to find a reference:
A similar question was asked recently:
- ggplot2: Is there a fix for jagged, poor-quality text produced by geom_text()?
- How to nicely annotate a ggplot2 (manual)
这篇关于ggplot:由geom_text打印的文本不清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文