Skip to content

Instantly share code, notes, and snippets.

@gtgrthrst
Created May 8, 2021 15:42
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/effa61dffe83b2165a7ca83a3917eb8a to your computer and use it in GitHub Desktop.
Save gtgrthrst/effa61dffe83b2165a7ca83a3917eb8a to your computer and use it in GitHub Desktop.
install.packages("ggplot2")
library(ggplot2)
data1 <- data.frame(x = c("A", "B", "C", "D"),
width = c(25, 50, 75, 100),
height = c(100, 75, 50, 25))
data1$w <- cumsum(data1$width)
data1$wm <- data1$w - data1$width
data1$wt <- with(data1, wm + (w - wm)/2)
p <- ggplot(data1, aes(ymin = 0))
p + geom_rect(aes(xmin = wm, xmax = w,
ymax = height, fill = x))+
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