如何在ggplot2的facet_wrap中将第二列strip label移至右侧?
问题需求
我希望将分面图(facet graph)第二列的strip label移至右侧,如图中标注所示。以下是我当前使用的代码及示例数据集:
当前代码
library(reshape2) library(tidyverse) library(ggh4x) library(scales) library(ggplot2) #step 1: 处理数据 df <- melt(df, id=c("Specie","Treatment")) head(df) #绘图部分 left <- scale_y_continuous(labels = number_format(accuracy = 0.01)) right <- scale_y_continuous(labels = number_format(accuracy = 0.01),position = "right") ggplot(df1, aes(x = Specie, y = mean, fill = Treatment, colour=Treatment)) + geom_col(position = position_dodge(), width = 0.8)+ facet_wrap(~ variable, scales = "free_y", ncol = 2, labeller = label_parsed, strip.position = "left")+ geom_errorbar(aes(ymin = mean, ymax = mean + sd), width = 0.2, position = position_dodge(0.9)) +theme_bw()+ geom_text(aes(y = mean+sd,label = label),position = position_dodge(0.9), size = 3.5, vjust=-0.2, family="serif", colour="black")+ geom_text(aes(y = Q1/2,label = letter),size = 3.5, family="serif", colour="#000000")+ scale_fill_manual(values=c('#DEB887','#CD853F'))+ scale_color_manual(values=c('#DEB887','#CD853F'))+ facetted_pos_scales(y = list(left, right, left, right, left, right))+ #coord_flip()+ theme(axis.text.x = element_text(face = "italic"), strip.placement = "outside", strip.background = element_blank())
示例数据集
| Treatment | Specie | Pn | Gs | E | WUE |
|---|---|---|---|---|---|
| CT | S. commersonii | 4.8100 | 0.0736 | 1.1100 | 4.3333 |
| CT | S. commersonii | 11.5000 | 0.4660 | 5.4400 | 2.1140 |
| CT | S. tuberosum 2x | 16.4000 | 0.4930 | 5.5200 | 2.9710 |
| CT | S. tuberosum 2x | 4.2400 | 0.0862 | 1.8100 | 2.3425 |
| CT | S. chacoense | 3.9200 | 0.0426 | 0.7160 | 5.4749 |
| CT | S. chacoense | 7.9000 | 0.1500 | 1.9400 | 4.0722 |
| HS | S. commersonii | 10.1000 | 0.3520 | 6.0300 | 1.6750 |
| HS | S. commersonii | 6.8500 | 0.3700 | 5.4600 | 1.2546 |
| HS | S. tuberosum 2x | 4.7100 | 0.0205 | 0.8400 | 5.6071 |
| HS | S. tuberosum 2x | 4.3400 | 0.0314 | 1.2450 | 3.4859 |
| HS | S. chacoense | 13.8000 | 0.2450 | 6.4800 | 2.1296 |
| HS | S. chacoense | 14.4000 | 0.1700 | 5.5100 | 2.6134 |
内容的提问来源于stack exchange,提问作者Ikram Bashir
相关产品推荐
相关产品推荐

