在图中,是否可能稍微抖动状态缩写标签,以便它们不重叠?如果我使用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,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',0)))
或多个标签
df$jit<-with(df,ifelse(abbrev == "KS" | abbrev == "LA",2)) +geom_text(fontface = "bold",position=position_jitter(width=df$jit,height=df$jit))