在图中,是否可以稍微抖动状态缩写标签以使它们不重叠?如果我使用 check_overlap = TRUE ,那么它会删除一些重叠的观察结果,但我不希望这样。我也不想要 geom_label_repel
,因为它的标签突出并穿过我包含的 45 度线(我不希望发生这种情况)
这是我的代码的相关部分供引用:
ggplot(df, aes(x = huff_margin_dem, y = margin16dem_state, label = abbrev)) +
geom_abline(intercept = 0) +
geom_text(fontface = "bold")
最佳答案
您尝试过position=position_jitter()
吗?您可以根据自己的选择调整宽度
和高度
。
ggplot(df, aes(x = huff_margin_dem, y = margin16dem_state, label = abbrev)) +
geom_abline(intercept = 0) +
geom_text(fontface = "bold",position=position_jitter(width=1,height=1))
编辑 仅操作某个标签的示例
+geom_text(fontface = "bold",
position=position_jitter(width=ifelse(df$abbrev=='KS',1,0),
height=ifelse(df$abbrev=='KS',1,0)))
或多个标签
df$jit<-with(df, ifelse(abbrev == "KS" | abbrev == "LA", 1, 2))
+geom_text(fontface = "bold",
position=position_jitter(width=df$jit,height=df$jit))
关于r - 如何抖动/删除 geom_text 标签的重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40542685/