Bar chart with ID indicator
Maybe something like this:
- Bring you data in lang format with
pivot_longer
- transform
Id
andname
to factor type - use
ggplot
library(tidyverse)
df %>%
pivot_longer(
-Id
) %>%
mutate(Id = factor(Id),
name=factor(name, levels = c("total_steps", "total_sleeps", "total_calories"))) %>%
ggplot(aes(x=Id, y=value, fill=name, label=value))+
geom_col(position=position_stack()) +
geom_text(aes(label = value,family = "serif"), position = position_stack(vjust = 0.5))+
theme_bw()
data:
df <- structure(list(Id = c(8378563200, 5577150313, 4702921684, 4388161847,
7086361926, 6962181067, 4445114986, 5553957443, 4319703577, 1503960366,
2026352035, 3977333714, 6117666160, 8792009665, 4020332650, 2347167796
), total_steps = c(8377719, 6477458, 7174818, 7710336, 6972600,
9412809, 4163404, 8276690, 5858684, 9390475, 4832044, 9227036,
3551544, 806370, 562272, 2570310), total_sleeps = c(427769, 336960,
349432, 285324, 337125, 430528, 334335, 445408, 384183, 279217,
439363, 246660, 241304, 189515, 86645, 120636), total_calories = c(3302554,
2620514, 2482164, 2205930, 1909368, 1904733, 1897616, 1802526,
1642368, 1407725, 1337280, 1271480, 1139616, 853605, 591680,
551730)), row.names = c(NA, -16L), class = c("tbl_df", "tbl",
"data.frame"))