gpt4 book ai didi

r - 每个 facet_grid 的 ggplot2 个人 ylabs

转载 作者:行者123 更新时间:2023-12-04 03:08:14 27 4
gpt4 key购买 nike

我用 Inkscape 编辑了这个图,但是我想知道是否有办法在 ggplot 环境中完成它?

enter image description here

我在网上快速搜索了一下,但没有成功。有人可以给我一个解决方法吗?

我真的很感激,因为我认为这是一种非常常见的情节类型。

该图的代码是:

var3 %>% 
gather(-(exp:rep), key = "variable", value ="value") %>%
mutate(variable = recode(variable,
diam = "Lesion diameter",
dles = "Lesion density",
sev = "Disease severity")) %>%
ggplot(aes(x = Iso, y = value)) +
geom_boxplot(aes(fill=factor(exp)),
position = position_dodge(width = 0), alpha = 0.5,
width =0.3) +
facet_grid(variable~Cv,
labeller = labeller(Cv = label_both, variable = label_value),
scales = "free")+
scale_y_continuous(labels=scaleFUN)+
theme_juan(9, "top", "center")+
scale_fill_manual(values = c("grey70","grey30"),
labels = c("Exp. 1","Exp. 2"), name = "")

作为 var3 数据框看起来像:

# A tibble: 72 x 7
exp Cv Iso rep sev dles diam
<dbl> <fctr> <fctr> <dbl> <dbl> <dbl> <dbl>
1 1 BMX_Potencia MT 1 0.17262317 1.8924050 0.2400000
2 1 BMX_Potencia MT 2 0.14700000 2.1483445 0.3000000
3 1 BMX_Potencia MT 3 0.01404289 1.3623602 0.2133333
4 1 BMX_Potencia MT 4 0.11933333 1.3160049 0.2900000

最佳答案

你可以试试这个解决方法

library(ggplot2)
library(grid)

d <- data.frame(x=1:4, f1=gl(2,2, labels=c("A","B")), f2=rep(letters[1:2],each=2))

p1 <- ggplot(d, aes(x,x)) + geom_blank() +
facet_grid(f1~f2)

p2 <- p1 + facet_grid(f1~f2, switch = 'y',
labeller = labeller(f1=c(A="this", B="that")))+
theme(strip.placement.y = "outside",
strip.text.y = element_text(angle = 90),
strip.background = element_blank())

g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)

grid.newpage()
grid.draw(gridExtra::gtable_cbind(g2[,-ncol(g2)], g1[,ncol(g1)-3]))

enter image description here

关于r - 每个 facet_grid 的 ggplot2 个人 ylabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47189625/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com