[英]How to annotate the line at ggplot?
I want to annotate each line with factor variable (chain.length) like shown on the picture. 我想用如图所示的因子变量(chain.length)注释每一行。 How would I do it?
我该怎么办?
Here is the code for picture above. 这是上面图片的代码。
ggplot(mz_rt, aes(rt, mz, size = acex, colour = as.factor(double.bonds))) +
geom_line(aes(group = as.factor(chain.len)), colour = "grey", size = 0.3) +
geom_point() +
scale_radius(breaks = seq(from = 0, to = 1, by = 0.2)) +
theme(legend.position="bottom") +
theme_light()
Create an annotation layer by annotate function ( https://ggplot2.tidyverse.org/reference/annotate.html ). 通过注释功能( https://ggplot2.tidyverse.org/reference/annotate.html )创建注释层。 You need to specify positioning aesthetics.
您需要指定定位美学。
library(tidyverse)
library(ggplot2)
data(iris)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(size = 1.5 ,alpha = 0.7) +
annotate("segment", x = 5, xend = 5.5, y = 2.2, yend = 2.4, colour = "blue") +
annotate("text", x = 5, y = 2.15, label = "Some text")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.