2012-07-23 33 views
13

使用geom_text打印的文本不是很清楚。我怎样才能让它更清晰?ggplot:由geom_text打印的文本不清晰

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") 

enter image description here

+0

可能重复[GGPLOT2:有没有参差不齐,劣质的修复由geom_text()生成的文本?](http://stackoverflow.com/questions/10952832/ggplot2-is-there-a-fix-for-jagged-poor-quality-text-produced-by-geom-text) – 2012-07-23 20:17:27

+0

一个简单的解决方法是在'geom_text'中使用参数'check_overlap = TRUE' – 2017-10-03 18:10:59

回答

21

使用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") 

enter image description here


的原因是,geom_text overplots对于每一行文字数据帧中的数据,只有一次绘制文字annotate。正是这种重叠绘图导致了大胆的像素化文本。

我确信这个问题最近回答了。我会尽力找到一个参考: 类似的问题最近被问: