공통 X 축 제목과 공통 Y 축 제목을 만들고 싶은 플롯 배열이 있습니다. 예로서:
library(ggplot2)
library(cowplot)
library(ggpubr)z
theme_set(theme_cowplot())
df <- data.frame(x = 1:12, y = (1:12)^2)
df$grp = c('Some', 'Things', 'In a legend')
p <- ggplot(df, aes(x, y, color=grp)) + geom_point()
leg <- get_legend(p)
leg <- as_ggplot(leg)
p = p + theme(legend.position = "none")
plot_grid(
p, p, leg,
p, p, leg,
ncol = 3, rel_widths=c(2,2,1)
)
몇 가지 읽은 후 옵션으로 ggdraw
. 그러나 나는 그것이 어떻게 잘 작동하는지 모르고 내가 원하는 것을 얻는 방법을 알지 못합니다 (하나 Y
는 y 축에, 다른 하나 X
는 x 축에 있음). 아래는 내가 시도한 것입니다.
df <- data.frame(x = 1:12, y = (1:12)^2)
df$grp = c('Some', 'Things', 'In a legend')
p <- ggplot(df, aes(x, y, color=grp)) + geom_point()
leg <- get_legend(p)
leg <- as_ggplot(leg)
p = p + theme(legend.position = "none",axis.title.x =element_blank(),axis.title.y =element_blank()) # I remove x and y titles for the plots
P <-plot_grid(
p, p, leg,
p, p, leg,
ncol = 3, rel_widths=c(2,2,1)
)
P
ggdraw
원하는 위치에 하나의 x 축 제목이있는 플롯 배열을 만들었습니다. 그러나 나는 y 축에 대해 동일한 것을 얻는 방법을 모릅니다. 레이블을 추가하기 위해 y 축 여백을 늘리는 방법을 모르겠습니다. 다음은 지금까지 시도한 코드입니다.P1 <- ggdraw(add_sub(P , "X", vpadding=grid::unit(0.8,"lines"), # With `0.8` I add some space in the X margin.
y=2, x=1, vjust=1, # With `y` and `x` I can indicate the coordinates for my desired text
angle=0) # With this I can change the orientation of the text
)
P1
누구든지 ggdraw
다른 함수를 사용 하거나 사용하여 일반적인 x 및 y 축을 만드는 방법을 알고 있습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다