2016-04-11 4 views
3

Я создал график Sepal.Length и Sepal.Width (с использованием набора диафрагмы) с ggplot2.Добавление дополнительной точки в графе ggplot2

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

Выполняется отлично, но теперь я хотел бы добавить отдельную точку к графику синим цветом. Так, например:

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

Любые мысли о том, как я могу это сделать?

ответ

2

Добавить еще один слой:

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

Использование аннотировать:

ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species)) + 
    geom_point() + 
    annotate("point", x = 5.6, y = 3.9, colour = "blue") 
3
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

Смежные вопросы