ggarrange: 공유 y 및 x 축으로 여러 플롯 결합: 플롯을 동일한 비율로 유지하면서 공유 y 축 하나만 정렬

라이브

저는 ggpubr::ggarrangey축과 x축을 공유하는 다중 플롯을 만들곤 했습니다. 내가 겪고있는 유일한 문제는 y 축이있는 첫 번째 플롯이 전체 그림의 비율을 벗어난 다른 3 개의 플롯보다 작다는 것입니다.

따라서 첫 번째 플롯을 다른 3개의 플롯에 비례하지 않게 하지 않고 하나의 y 랩만 표시하는 솔루션을 찾고 있습니다. 이미 한동안 잠잠했던 이후로 이 문제에 대한 해결책을 찾고 있었기 때문에 도움을 주시면 감사하겠습니다.

지금까지의 접근 방식은 플롯(p) 2,3,4에서 y 랩을 제거하고 p1에 그대로 두는 것이었습니다.

이것은 내 코드입니다.

library(ggplot2)
  library(ggpubr)
  library(dplyr)
p1 <-  ggplot(arrange(ploughed1, Horizont), aes(Ferment, RAI_II,  fill = factor(Horizont, levels=c("4","3","2","1"))))+
    geom_bar(stat = "identity", position = "dodge")+
    scale_fill_manual(values = c("#FF9933", "#CC6600","#663300","#000000"))+
    guides(fill = guide_legend(reverse = TRUE))+
    labs(fill="Horizon")+
    ylim(0,200)+
    theme_bw()+
    facet_wrap(~compost)+
    theme(strip.text = element_text(size = 7),
          panel.spacing = unit(0.2, "lines"))+
    geom_col(position = position_stack(reverse = TRUE))+
    labs(x="Ferment", y = "RAI_II=Rooting*Scheme*Active",  title = "P- ")

p2 <-  ggplot(arrange(ploughed2, Horizont), aes(Ferment, RAI_II,  fill = factor(Horizont, levels=c("4","3","2","1"))))+
    geom_bar(stat = "identity", position = "dodge")+
    scale_fill_manual(values = c("#FF9933", "#CC6600","#663300","#000000"))+
    guides(fill = guide_legend(reverse = TRUE))+
    labs(fill="Horizon")+
    ylim(0,200)+
    theme_bw()+
    theme(axis.text.y = element_blank(),
          panel.spacing = unit(0.2, "lines"),
          strip.text = element_text(size = 7))+
    facet_wrap(~compost)+
    geom_col(position = position_stack(reverse = TRUE))+
    labs(x="Ferment",  title = "P+ ")+ 
    rremove("ylab")

  p3 <-  ggplot(arrange(reduced1, Horizont), aes(Ferment, RAI_II,  fill = factor(Horizont, levels=c("4","3","2","1"))))+
    geom_bar(stat = "identity", position = "dodge")+
    scale_fill_manual(values = c("#FF9933", "#CC6600","#663300","#000000"))+
    guides(fill = guide_legend(reverse = TRUE))+
    labs(fill="Horizon")+
    ylim(0,200)+
    theme_bw()+
    theme(axis.text.y = element_blank(),
          panel.spacing = unit(0.2, "lines"),
          strip.text = element_text(size = 7))+
    facet_wrap(~compost)+
    geom_col(position = position_stack(reverse = TRUE))+
    labs(x="Ferment",  title = "RT- ")+ 
    rremove("ylab")
  
  p4 <-  ggplot(arrange(reduced2, Horizont), aes(Ferment, RAI_II,  fill = factor(Horizont, levels=c("4","3","2","1"))))+
    geom_bar(stat = "identity", position = "dodge")+
    scale_fill_manual(values = c("#FF9933", "#CC6600","#663300","#000000"))+
    guides(fill = guide_legend(reverse = TRUE))+
    labs(fill="Horizon")+
    ylim(0,200)+
    theme_bw()+
    theme(axis.text.y = element_blank(),
          panel.spacing = unit(0.2, "lines"),
          strip.text = element_text(size = 7))+
    facet_wrap(~compost)+
    geom_col(position = position_stack(reverse = TRUE))+
    labs(x="Ferment",  title = "RT+ ")+ 
    rremove("ylab")
ggarrange(p1, p2, p3, p4, nrow=1, common.legend = TRUE)

출력 .png

출력 이미지: 1

또한 p2,p3,p4에 있는 y lab과 text를 제거하지 않고 ggarrange 함수에서 풀려고 했는데 결과가 같습니다.

ggarrange(p1, p2+ 
            theme(axis.text.y = element_blank(),
                  axis.ticks.y = element_blank(),
                  axis.title.y = element_blank() ), p3+ 
            theme(axis.text.y = element_blank(),
                  axis.ticks.y = element_blank(),
                  axis.title.y = element_blank() ), p4+ 
            theme(axis.text.y = element_blank(),
                  axis.ticks.y = element_blank(),
                  axis.title.y = element_blank() ) , nrow=1,  common.legend = TRUE)
스테판

다른 패키지가 옵션인 경우 을 사용하는 것이 좋습니다 patchwork. 실제 데이터를 모방하기 위해 일부 편의 기능을 사용하여 중복된 코드와 임의의 예제 데이터를 줄입니다.

library(ggplot2)
library(patchwork)
library(dplyr)

ploughed1 <- data.frame(
  Horizont = rep(1:4, 4),
  RAI_II = runif(16, 10, 50),
  Ferment = rep(c("-", "+"), each = 8),
  compost = rep(c("- Compost", "+ Compost"), each = 4)
)

plot_fun <- function(x, title) {
  ggplot(arrange(x, Horizont), aes(Ferment, RAI_II, fill = factor(Horizont, levels = c("4", "3", "2", "1")))) +
    geom_bar(stat = "identity", position = "dodge") +
    scale_fill_manual(values = c("#FF9933", "#CC6600", "#663300", "#000000")) +
    guides(fill = guide_legend(reverse = TRUE)) +
    ylim(0, 200) +
    theme_bw() +
    facet_wrap(~compost) +
    theme(
      strip.text = element_text(size = 7),
      panel.spacing = unit(0.2, "lines")
    ) +
    geom_col(position = position_stack(reverse = TRUE)) +
    labs(x = "Ferment", y = "RAI_II=Rooting*Scheme*Active", fill = "Horizon", title = title)
}

remove_y <- theme(
  axis.text.y = element_blank(),
  axis.ticks.y = element_blank(),
  axis.title.y = element_blank()
)
p <- list(
  plot_fun(ploughed1, "P-"),
  plot_fun(ploughed1, "P+") + remove_y,
  plot_fun(ploughed1, "RT-") + remove_y,
  plot_fun(ploughed1, "RT+") + remove_y
)
wrap_plots(p, nrow = 1) + plot_layout(guides = "collect")

스케일로 인해 첫 번째 플롯 patchworkggpubr:ggarrange스퀴즈 패싯 을 사용하여 각 플롯에서 모든 패싯이 동일한 너비인 경우와 비교 y:

ggpubr::ggarrange(plotlist = p, nrow = 1, common.legend = TRUE)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

TOP 리스트

  1. 1

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  2. 2

    std :: regex의 일관성없는 동작

  3. 3

    JSoup javax.net.ssl.SSLHandshakeException : <url>과 일치하는 주체 대체 DNS 이름이 없습니다.

  4. 4

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  5. 5

    Xcode10 유효성 검사 : 이미지에 투명성이 없지만 여전히 수락되지 않습니까?

  6. 6

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  7. 7

    Ionic 2 로더가 적시에 표시되지 않음

  8. 8

    Seaborn에서 축 제목 숨기기

  9. 9

    C #에서 'System.DBNull'형식의 개체를 'System.String'형식으로 캐스팅 할 수 없습니다.

  10. 10

    복사 / 붙여 넣기 비활성화

  11. 11

    ArrayBufferLike의 typescript 정의의 깊은 의미

  12. 12

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  13. 13

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  14. 14

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  15. 15

    PRNG 기간보다 순열이 더 많은 목록을 무작위로 섞는 방법은 무엇입니까?

  16. 16

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  17. 17

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  18. 18

    잘못된 구성 개체입니다. Webpack이 Angular의 API 스키마와 일치하지 않는 구성 개체를 사용하여 초기화되었습니다.

  19. 19

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  20. 20

    R의 마침표와 숫자 사이에 문자열 삽입

  21. 21

    Assets의 BitmapFactory.decodeStream이 Android 7에서 null을 반환합니다.

뜨겁다태그

보관