1

I'm new to R. I was trying to plot the last value of each variable in a data frame on top of a boxplot. Without success I was trying:

ggplot(iris, aes(x=Species,y=Sepal.Length)) + 
  geom_boxplot() + 
  geom_point(iris, aes(x=unique(iris$Species), y=tail(iris,n=1)))

Thanks, Bill

RedOakBill
  • 51
  • 1
  • 6

1 Answers1

3

One approach is

library(tidyverse)
iris1 <- iris %>% 
             group_by(Species) %>% 
             summarise(LastVal = last(Sepal.Length))
ggplot(iris, aes(x=Species,y=Sepal.Length)) + 
          geom_boxplot() + 
          geom_point(data = iris1, aes(x = Species, y = LastVal))
akrun
  • 874,273
  • 37
  • 540
  • 662