簡體   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