使用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")
Run Code Online (Sandbox Code Playgroud)

And*_*rie 31
使用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")
Run Code Online (Sandbox Code Playgroud)

原因是geom_text过度annotate绘制了数据框中每行数据的文本,而只将文本绘制一次.正是这种过度绘制导致了粗体的像素化文本.
我相信这个问题最近得到了回答.我会尝试找一个参考:
最近有一个类似的问题:
扩展 Dave Gruenewald 的评论,geom_text现在有了check_overlap选择。请参阅tidyverse 参考:
check_overlap-- 如果TRUE,则不会绘制与同一层中先前文本重叠的文本。check_overlap在绘制时发生并按数据顺序发生。因此调用前应按标签列排列数据geom_text()。请注意,此参数不受geom_label().
library(ggplot2)
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", check_overlap = T)
Run Code Online (Sandbox Code Playgroud)