繁体   English   中英

ggplot geom_boxplot并使用geom_point绘制最后一个值

[英]ggplot geom_boxplot and plotting last value with geom_point

我是R的新手。我试图在Boxplot顶部的数据框中绘制每个变量的最后一个值。 没有成功,我正在尝试:

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

谢谢,比尔

一种方法是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM