簡體   English   中英

在 ggplot2 圖中添加一個額外的點

[英]Adding an extra point in a ggplot2 graph

我用 ggplot2 創建了一個 Sepal.Length 和 Sepal.Width(使用虹膜數據集)的圖。

  ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species)) + geom_point()

工作正常,但現在我想用藍色向圖形添加一個單獨的點。 例如:

  df = data.frame(Sepal.Width = 5.6, Sepal.Length = 3.9) 

關於我如何做到這一點的任何想法?

添加另一個圖層:

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species)) + 
  geom_point() +
  geom_point(aes(x=5.6, y=3.9), colour="blue")
library('ggplot2')

df = data.frame(Sepal.Width = 5.6, Sepal.Length = 3.9) 

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species)) +
  geom_point() +
  geom_point(data = df, col = 'blue')

在此處輸入圖片說明

使用注釋

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species)) + 
  geom_point() +
  annotate("point", x = 5.6, y = 3.9, colour = "blue")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM