ggplot2 + 截断y轴

利用patchwork可以做出坐标轴截断的样子。

require(ggplot2)
require(patchwork)
set.seed(13)
options(stringsAsFactors = FALSE)
name <- rep(LETTERS[1:10],3)
value <- runif(30)

data <- data.frame(name, value)
customer_theme <-  theme(axis.text.x = element_blank(),
                         axis.ticks.x = element_blank(),
                         axis.title = element_blank(),
                         panel.background = element_blank(),
                         axis.line = element_line(colour = "black"))


p1 <- ggplot(data = data, aes(x = name, y = value)) + 
  geom_bar(stat = "identity", position = "stack") +
  coord_cartesian(ylim = c(0,0.2)) #设置下面一半

p2 <- ggplot(data = data, aes(x = name, y = value)) + 
  geom_bar(stat = "identity", position = "stack") +
  coord_cartesian(ylim = c(0.24,3)) + 
  scale_y_continuous(breaks = # 按值设置breaks
                       seq(from = 0.24, to = 3, by = 0.5)) +
  labs( title = "Graph with broken y axis")

p2 /p1 & customer_theme 

你可能感兴趣的:(ggplot2 + 截断y轴)