Skip to content

Instantly share code, notes, and snippets.

@gtgrthrst
Created May 16, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtgrthrst/147f96e9bb997bc05076ccac297af55a to your computer and use it in GitHub Desktop.
Save gtgrthrst/147f96e9bb997bc05076ccac297af55a to your computer and use it in GitHub Desktop.
df <- data.frame(
group = c("A", "B", "C", "D", "E", "F"),
value = c(100, -15, 25, -50, 45, 25)
)
df$group <- factor(df$group, levels = df$group)
df$id <- seq_along(df$value)
df$end <- cumsum(df$value)
df$end <- c(head(df$end, -1), 0)
df$start <- c(0, head(df$end, -1))
ggplot(df, aes(x=group, y=value, fill=group))+theme_gray()+
geom_rect(aes(x = group, xmin = id -0.4, xmax = id + 0.45, ymin = end, ymax = start)) +
theme(axis.title=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank()) + #刪除XY軸
guides(fill = FALSE, color = FALSE, linetype = FALSE, shape = FALSE) #刪除圖例
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment