RStudio ggplot 名称点与 x 或 y 不同的列

RStudio ggplot name points with different column than x or y

我有以下数据集:

CATEGORY ID   Mode_A   Mode_B   Mean_A   Mean_A
A         1      4       2       2.1      3.4
A         2      1       2       4.2      2.7 
B         3      1       1       3.2      4.1 
B         4      4       2       1.5      1.2

example

我创建了以下情节:

ggplot(data = tabla_moda) + 
 geom_point(mapping = aes(x = Media_Impacto, y = Media_Esfuerzo, color = Moda_Impacto, size = Moda_Esfuerzo)
)

Graph

我正在尝试从我的数据集添加到图形 ID rowname 中的所有点

我试过:

ggplot(data = tabla_moda) + 
 geom_point(mapping = aes(x = Media_Impacto, y = Media_Esfuerzo, color = Moda_Impacto, size = Moda_Esfuerzo) +
               ggrepel::geom_text_repel(label = ID, nudge_x=0.45, nudge_y=0.1,check_overlap=T)
)

ggplot(data = tabla_moda, mapping = aes(x = Media_Impacto, y = Media_Esfuerzo, color = Moda_Impacto, size = Moda_Esfuerzo, label = rownames(ID))) + 
 geom_point()  +
  geom_text(label = ID, nudge_x=0.45, nudge_y=0.1,check_overlap=T)

但我总是得到 ID,同样的错误:

ID object not found

在此先感谢您的帮助

这是因为 ID 是数据集的一个变量,所以您应该始终将它包含在美学中,我认为这应该有效:

ggplot(data = tabla_moda, mapping = aes(x = Media_Impacto, y = Media_Esfuerzo, color = Moda_Impacto, size = Moda_Esfuerzo)) + 
geom_point()  +
geom_text(aes(label = ID), nudge_x=0.45, nudge_y=0.1,check_overlap=T)