我想在條形圖上顯示高于和低于平均值的范圍值的觀察次數文本。
我嘗試了以下
使用電動汽車資料集
輕資料爭吵以洗掉空格和 -
uj5u.com熱心網友回復:
你在尋找這樣的東西嗎?
library(tidyverse)
EV <- read_csv("evdataset.csv")
EV$range_norm <- (EV$`Electric Range` - mean(EV$`Electric Range`))/sd(EV$`Electric Range`)
EV$range_type <- ifelse(EV$range_norm > 0, "above", "below")
plot_data <- EV |> group_by(Make, Drive, range_type) |>
summarize(count = n()) |>
mutate(count = ifelse(range_type == "above", count, -count)) |>
ungroup()
plot_order <- plot_data |>
group_by(Make) |>
summarize(totalcount = sum(count)) |>
arrange(totalcount) |>
pull(Make)
ggplot(plot_data, aes(x = fct_relevel(Make, plot_order),
y = count,
fill = range_type,
label = count))
geom_col()
geom_text(size = 3)
facet_wrap(~Drive)
coord_flip()
xlab("Make")
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/525505.html
標籤:r土工棒
上一篇:根據另一列計算出列值作為百分比值