简体   繁体   English

在 ggplot2 图中添加一个额外的点

[英]Adding an extra point in a ggplot2 graph

I have created a plot of the Sepal.Length and the Sepal.Width (using the iris dataset) with ggplot2.我用 ggplot2 创建了一个 Sepal.Length 和 Sepal.Width(使用虹膜数据集)的图。

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

Works fine but now I would like to add a seperate point to the graph with a blue color.工作正常,但现在我想用蓝色向图形添加一个单独的点。 So for example:例如:

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

Any thoughts on how I can accomplish this?关于我如何做到这一点的任何想法?

Add another layer:添加另一个图层:

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

在此处输入图片说明

Using annotate :使用注释

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