与ggrepel共享同一个图例框的单个点

问题描述

当我生成这样的图表时

ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,color=Species,label=Species)) + 
geom_label_repel()

每个点都有自己的标签。有没有办法创建一个图形,其中我们只有 3 个文本框(在这种情况下,因为我们有 3 个 Species),并且与该物种对应的所有点都用线绑定?

谢谢!

解决方法

我喜欢 #include <iostream> #include <complex> #include <math.h> using namespace std; int main() { int a,b,c,d; float x1,x2; cout << "Please input values for a,b and c to represent the variables in equation : ax^2 + bx + c" << endl; // Dont know how to raise 2 instead of using ^2 cin >> a >> b >> c; d = (b * b) - (4 * a * c); cout << d << endl; cout << (-b + sqrt(d))/(2 * a); } 几何体:

ggforce::geom_mark_*

enter image description here

,

您可以使用 Jon Springstat_ellipse 完成类似于 annotate 所提供的内容。

library(ggplot2)


ggplot(iris) +
  geom_point(aes(x = Sepal.Length,y = Sepal.Width,color = Species)) +
  stat_ellipse(aes(x = Sepal.Length,color = Species),level = 0.998) +
  annotate(
    geom = "text",x = 3.9,y = 2,label = "Versicolor",hjust = "left",color = 'dark green'
    ) +
  annotate(
    geom = "text",x = 4.2,y = 4,label = "Setosa",color = 'red'
    ) +
    annotate(
    geom = "text",x = 7.1,y = 4.1,label = "Virginica",color = 'blue'
    )

reprex package (v0.3.0) 于 2021 年 3 月 17 日创建

,

感谢乔恩和埃里克,

然而,这两种解决方案在显示我的数据时有点混乱,所以我更喜欢用线绑定的点而不是单个标签。

谢谢, 罗伯特

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...