ggplot geom_boxplot 并用 geom_point 绘制最后一个值
ggplot geom_boxplot and plotting last value with geom_point
我是 R 的新手。我试图在箱线图顶部的数据框中绘制每个变量的最后一个值。没有成功我正在尝试:
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))
我是 R 的新手。我试图在箱线图顶部的数据框中绘制每个变量的最后一个值。没有成功我正在尝试:
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))