R 排斥ggplot中的几何图形标签和文本。并根据大小对几何点进行排序

R 排斥ggplot中的几何图形标签和文本。并根据大小对几何点进行排序,r,ggplot2,ggrepel,R,Ggplot2,Ggrepel,我有两个数据帧,如下所示: df1 <- data.frame( party = c("Blue Party", "Red Party"), dim1 = c(0.03, -0.04), dim2 = c(-0.05, 0.02), sz = c(34, 42) ) df2 <- data.frame( var = c("Economic", "Gov trust", "Inst trust", "Nationalism", "Religiosity"), d

我有两个数据帧,如下所示:

df1 <- data.frame(
  party = c("Blue Party", "Red Party"),
  dim1 = c(0.03, -0.04),
  dim2 = c(-0.05, 0.02),
  sz = c(34, 42)
)
df2 <- data.frame(
  var = c("Economic", "Gov trust", "Inst trust", "Nationalism", "Religiosity"),
  dim1 = c(0.1, -0.5, 0, 0.6, 0.4),
  dim2 = c(0.1, 0.6, 0, 0, 0.3)
)
因此:

功能
geom_label_repel
geom_text_repel
可防止政党标签和文本重叠,但如何使标签和文本相互排斥

我的第二个问题是我想对点进行排序,最小的在前面,最大的在后面。这怎么可能呢


谢谢你的帮助

要对点进行重新排序,这似乎是可行的,
df1我需要一种更系统的方法,因为我正在创建几十个带有for循环的图形。
ggplot(df1, aes(x = dim1, y = dim2, color = party)) +
  geom_point(size = df1$sz) +
  scale_size_area() +
  scale_x_continuous(limits = c(-1.5, 1.5)) +
  scale_y_continuous(limits = c(-1.5, 1.5)) +
  geom_label_repel(aes(label = party),
                   box.padding   = 1,
                   point.padding = 1.5,
                   force = 1) +
  geom_segment(aes(xend=0, yend=0, x=dim1, y=dim2), data=df2,
    arrow=arrow(length=unit(0.20,"cm"), ends="first", type = "closed"), color="black") +
  geom_text_repel(aes(x=dim1, y=dim2, label=var),
    data = df2, color = "black", size = 3, force = 1)