我正在為幾個組(Loc)繪制geom_point,并希望另外有一條線來表示每個組的點的平均值。這些組應該根據每組的Size的平均值來排序。我試圖通過reorder(Loc, Size.Mean)來做到這一點,但是它并沒有重新排序。
ggplot(data,/span>aes(Loc, 尺寸,顏色=Loc))
geom_point()
geom_point(data %>%)
group_by(Loc) %>%
summarise(Size. Mean = mean(Size)),
mapping = aes(y = size。 Mean, x = reorder(Loc, Size. Mean)),
color = "black"。 形狀 = '-')
theme_pubr(base_size=8)
scale_y_continuous(trans="log10")
主題(axis.text。 x = element_text(angle = 90。 hjust = 1))
主題(legend.position = "none"/span>)
uj5u.com熱心網友回復:
如果變數是一個因素,ggplot根據其水平對離散的x點進行排序:
library(tidyverse)
iris_means<-
iris %>%。
group_by(Species) %>%
summarise(mean = mean(Sepal. 長度)) %>%
安排(-平均)
虹膜%>%
mutate(Species = Species %> %因子(水平= iris_means$Species)) %> %
ggplot(aes(Species, Sepal. 長度))
geom_point()
geom_crossbar(data = iris_means。 映射= aes(y = mean, ymin = mean, ymax = mean)。 color = "red")

創建于2021-09-10,由reprex包(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318952.html
標籤:
