ggpot2 散点图添加注释

library(ggplot2)
  
p<-ggplot(iris,aes(iris$Petal.Length, iris$Sepal.Width))
p<-p+geom_point(aes(color= iris$Species ))+scale_color_manual(values = c("red", "grey","blue"))+theme(legend.position = "right")

给每个点加上对应的注释

p+geom_text(data=iris,mapping=aes(label=paste(iris$Sepal.Width)),vjust=1.5,colour="black",size=3)

根据坐标添加文本

p+annotate("text", x=iris$Petal.Length[1], y=iris$Sepal.Width[1], label=iris$Species[1],vjust=1.5,colour="green", size=6)+
      annotate("rect", xmin=1.25, xmax=1.55, ymin=3.41, ymax=3.49, alpha=.1,color="blue")

根据坐标添加数学表达式

p + annotate("text",x=5.5,y=4, parse=TRUE,label="x %->% y",size=5)+
      annotate("rect", xmin=5.3, xmax=5.7, ymin=3.9, ymax=4.1, alpha=.1,color="blue")

?plotmath查看数学表达式书写方法

筛选数据,标记符合要求的数据

library(ggrepel)
ggplot(iris, aes(x = Petal.Length, y = Sepal.Width)) +
  geom_point(aes(color = Species)) +
  scale_color_manual(values = c("red", "grey","black")) +
  theme_bw(base_size = 12) + theme(legend.position = "bottom") +
  geom_text_repel(
    data = subset(iris, Species=="setosa"),
    aes(label = Sepal.Length),
    size = 3,
    box.padding = unit(0.35, "lines"),
    point.padding = unit(0.3, "lines")
  )
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 恋人,走着走着就散了;亲人,走着走着就老了;青春,走着走着已为过去式了;岁月,走着走着就蹉跎了......流光飞逝...
    零的作用阅读 222评论 0 0
  • 陈梦家 我悄悄地绕过那一条小路, 不敢碰落一颗光亮的露; 是一阵温柔的风吹过, 不是我,不是我! 我暗暗地藏起那串...
    小王子的狐狸先森阅读 230评论 0 0
  • 自己没有喜欢的歌手,但却喜欢听歌。 喜欢有故事的歌词,喜欢歌曲下有趣的评论。 最近《纸短情长》这首歌貌似很火,因为...
    仁青木子阅读 437评论 1 2
  • 国内知名时尚设计总监凯拉曾经说过:“爱一个人,如人饮水,冷暖自知,幸不幸福、合不合适 只有自己知道。如果感受不到彼...
    Z较瘦阅读 827评论 0 0

友情链接更多精彩内容