我是R和ggplot2
的新手。我正在使用ggplot2
,但我无法让check_overlap=TRUE
对我的geom_text产生任何影响。以下是我的代码示例:
require(ggplot2)
LV_plot = ggplot(plotFrame,aes(x=Age,y=fit))
#... plotting other things
my_text = geom_text(data=myDataFrame,mapping=aes(x=Age,y=myDataFrame$firstVolume, label=paste(myDataFrame$firstVolume)),angle=70,size=6,check_overlap=TRUE)
LV_scatterNorm = geom_point(data=myDataFrame,aes(x=Age,y=firstVolume),size=4.0)
LV_lineNorm = geom_line(data=myDataFrame,aes(x=Age,y=firstVolume),size=1.2)
这会创建多个文本元素,但check_overlap = TRUE对它们的重叠没有影响 - 它们在大多数时间都会重叠。
这是我的数据:
myDataFrame:
firstVolume Age
1 26502.54 56
2 28335.54 57
plotFrame:
Age fit se sd
1 43 10481.39 2555.560 16036.31
2 44 11164.03 2390.339 16036.31
3 45 11849.98 2225.044 16036.31
4 46 12537.78 2063.854 16036.31
5 47 13225.95 1910.410 16036.31
6 48 13913.05 1767.397 16036.31
7 49 14597.60 1636.212 16036.31
8 50 15278.15 1516.911 16036.31
9 51 15950.26 1408.477 16036.31
10 52 16612.87 1315.257 16036.31
...etc.
我的结果如下:
这是在R 3.1.1中。我做错了什么?
(我试图安装ggrepel,但似乎ggrepel不适用于此版本的R。)
谢谢!
答案 0 :(得分:1)
由于没有示例数据,我使用包中的示例数据尝试了这一点。因此,check_overlap
工作正常。
如果标签无法避免重叠,您可能需要缩小标签尺寸。
require(ggplot2)
data("mtcars")
mtcars
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))
p
p + geom_text()
# Avoid overlaps
p + geom_text(check_overlap = TRUE)
如果这不能解决您的问题,请提供可重复的示例,我会相应地更新我的答案。