问题描述
当我生成这样的图表时
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_*
,
您可以使用 Jon Spring
和 stat_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 日创建
,感谢乔恩和埃里克,
然而,这两种解决方案在显示我的数据时有点混乱,所以我更喜欢用线绑定的点而不是单个标签。
谢谢, 罗伯特