微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决与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 日创建

,

感谢乔恩和埃里克,

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

谢谢, 罗伯特

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?