Reversing y-axis in an individual ggplot facet

后端 未结 1 675
鱼传尺愫
鱼传尺愫 2020-12-20 09:06

I am plotting a range of different data measured on the same individuals next to each other in facets. For some types of data a positive value is \"good\" and for some a neg

相关标签:
1条回答
  • 2020-12-20 10:04

    I'm not sure if that's possible, so I would opt for a solution using the grid.arrange function from the gridExtra package.

    library(gridExtra)
    library(ggplot2)
    
    dat <- data.frame(type = rep(c('A', 'B'), each = 10), x = 1:10, y = rnorm(20),
                      stringsAsFactors = FALSE)
    
    p_A <- ggplot(subset(dat, type == 'A'), aes(x, y)) + geom_point() + facet_wrap( ~ type, scales = 'free_y')+
        scale_y_continuous(breaks = c(-1,0,1))
    p_B <- ggplot(subset(dat, type == 'B'), aes(x, y)) + geom_point() + facet_wrap( ~ type, scales = 'free_y')+
        scale_y_reverse(breaks = c(-1,0,1))
    
    grid.arrange(p_A, p_B, nrow = 1)
    

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