我想用因子变量(chain.length)来注释每一行,如图所示。我该怎么做呢?

这是上面图片的代码。
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()发布于 2018-11-06 00:19:21
通过注解函数(https://ggplot2.tidyverse.org/reference/annotate.html)创建注释层。您需要指定定位美学。
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")

https://stackoverflow.com/questions/53158006
复制相似问题