Break Y-Axis in ggplot2

后端 未结 1 818
無奈伤痛
無奈伤痛 2020-12-19 13:59

This is like a similar question that I posted two years ago. I have the following dataset.

dat <- read.table(header=TRUE, text=\"
Age ColA    ColB    Col         


        
相关标签:
1条回答
  • 2020-12-19 14:30

    How's this:

    dat1$new_value <- ifelse(dat1$value<=3,dat1$value,ifelse(dat1$value<7,NA,dat1$value-2))
    dat1 <- dat1[!is.na(dat1$new_value) ,]
    
    p = ggplot(dat1, aes(x=Age, y=new_value, group=variable))
    p + geom_line(aes(colour = variable), size=1.2)+theme_bw()+
      theme(text = element_text(size=20),
            axis.text.x = element_text(angle=90, vjust=1)) +
      scale_y_continuous(breaks = 1:6, labels = c(1:3,"break",7:8))
    

    0 讨论(0)
提交回复
热议问题