ggpot2 散點(diǎn)圖添加注釋

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")

給每個(gè)點(diǎn)加上對應(yīng)的注釋

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

根據(jù)坐標(biāo)添加文本

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")

根據(jù)坐標(biāo)添加數(shù)學(xué)表達(dá)式

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查看數(shù)學(xué)表達(dá)式書寫方法

篩選數(shù)據(jù),標(biāo)記符合要求的數(shù)據(jù)

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")
  )
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 戀人,走著走著就散了;親人,走著走著就老了;青春,走著走著已為過去式了;歲月,走著走著就蹉跎了......流光飛逝...
    零的作用閱讀 221評論 0 0
  • 陳夢家 我悄悄地繞過那一條小路, 不敢碰落一顆光亮的露; 是一陣溫柔的風(fēng)吹過, 不是我,不是我! 我暗暗地藏起那串...
    小王子的狐貍先森閱讀 228評論 0 0
  • 自己沒有喜歡的歌手,但卻喜歡聽歌。 喜歡有故事的歌詞,喜歡歌曲下有趣的評論。 最近《紙短情長》這首歌貌似很火,因?yàn)?..
    仁青木子閱讀 434評論 1 2
  • 國內(nèi)知名時(shí)尚設(shè)計(jì)總監(jiān)凱拉曾經(jīng)說過:“愛一個(gè)人,如人飲水,冷暖自知,幸不幸福、合不合適 只有自己知道。如果感受不到彼...
    Z較瘦閱讀 814評論 0 0

友情鏈接更多精彩內(nèi)容