26

I have created a plot of the Sepal.Length and the Sepal.Width (using the iris dataset) with ggplot2.

  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?

3 Answers 3

36

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")
Sign up to request clarification or add additional context in comments.

1 Comment

I suspect this plots as many points in the same location as the amount of points being plotted. I had 7.1 million integers, and this slowed the plot generation down by about 30 seconds compared to annotate! Trying this with geom_text slowed it down more, with the text constantly flickering, as if being redrawn.
19
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')

enter image description here

Comments

19

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.