r - R从strip.background函数中删除边框的两侧
问题描述
数据框
df <- data.frame(
structure(list(biological_group = structure(1:15, .Label = c("A",
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O"), class = "factor"), norm_expression = c(2L, 3L, 4L, 6L,
1L, 5L, 7L, 8L, 9L, 3L, 2L, 6L, 7L, 8L, 1L), SE = c(0.171499719,
0.089692493, 0.153777208, 0.188012958, 0.153776128, 0.192917199,
0.224766056, 0.231338325, 0.121716906, 0.094763028, 0.09635363,
0.069986333, 0.113681329, 0.094614957, 0.391182473), Group = structure(c(1L,
1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("",
"Plant Products", "Sugars"), class = "factor")), class = "data.frame", row.names = c(NA,
-15L), .Names = c("biological_group", "norm_expression", "SE",
"Group")))
示例代码
library(ggplot2)
DFplot <- ggplot(df, aes(biological_group,norm_expression)) +
ylab("Relative Normalized\nExpression (∆∆Cq)") +
geom_bar(fill="black",stat="identity") +
theme(axis.title.x = element_blank())
DFplot2 <- DFplot+geom_errorbar(aes(ymin=norm_expression-SE,ymax=norm_expression+SE),width=0.5) +
geom_boxplot() +
facet_grid(~Group, scales = "free_x", switch = "x", space = "free_x") +
scale_y_continuous(expand = c(0,0), labels = scales::number_format(accuracy = 0.1)) +
theme_classic()
我想从带状文本标签(由 strip.background 指定)中删除垂直线,如下所示:
我意识到我可以只使用 photoshop 或其他东西,但我有几个图表要制作,所以如果我可以在代码中指定它会更容易。
解决方案
这个答案很有帮助。
在你的情况下,你想找到strip-b
你的底部条来替代。
编辑:替换了意外移除的底部条的顶部栏。
library(grid)
q <- ggplotGrob(DFplot2)
lg <- linesGrob(x=unit(c(1,0),"npc"), y=unit(c(1,1),"npc"), gp=gpar(col="black", lwd=2))
for (k in grep("strip-b",q$layout$name)) {
q$grobs[[k]]$grobs[[1]]$children[[1]] <- lg
}
grid.draw(q)
推荐阅读
- java - 数据未显示在回收站视图中
- android - 升级 Flutter 应用时如何升级 Android 和 iOS 部分?
- javascript - Axios GET Request 在 Postman 中工作但抛出 400 错误 - Redux
- c# - 具有弱命名引用的 C# 强命名程序集在一种上下文中工作,但在另一种情况下不工作
- c# - 试图从一个类中创建一个对象列表,但它似乎不起作用
- fortran - 无法在 CodeBlocks 中打开模块文件“dflib.mod”错误
- python - 比格犬骨上的网络浏览器模块
- macos - 带有 Mac Catalyst 的 macOS 的 AVFoundation
- mysql - 从组中检索最后一条记录而不是第一条记录
- reactjs - TypeError:无法读取未定义的属性(读取“过滤器”)