[英]Removing panel border from nested grid labelling in ggplot theme
How can i remove the upper and both side borders in my grid plot using ggplot?如何使用 ggplot 删除网格 plot 中的上边框和两侧边框?
My code gives you following plot.我的代码为您提供了以下 plot。
ggplot(Plot_stomach[which(!Plot_stomach$Guild == "Piscivore"),],
aes(x=group, y=std_CR24, fill=group)) +
geom_bar(stat="identity", width=0.8, color = "black") +
geom_errorbar(aes(ymin=std_CR24-SE, ymax=std_CR24+SE), width=.2,
position=position_dodge(.9)) +
geom_text(aes(x=as.numeric(group), y= std_CR24+SE+5, label = N), size = 3) +
labs(x = "", y= expression(bold("Mean daily consmption rate (g prey kg"^-1~")"))) +
coord_flip() +
ylim(0,60) +
facet_nested(.~ Guild + Cluster2 + N_name) +
scale_fill_manual(name= "", values = c("Copepods" = "#cccccc",
"Euphausiids" = "#999999",
"Larvaceans" = "#666666",
"Other zooplankton" = "black",
"Ammodytids" = "#d11141",
"Clupeids" = "#ffc425",
"Gadids" = "#00b159",
"Other teleosts" = "#00aedb")) +
theme_bw() +
theme(panel.border = element_blank(),
strip.text.x = element_text(colour = "black", face = "bold", size =14),
strip.background = element_rect(color = "black", fill="white"),,
axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.text.x=element_text(colour="black", size = 14, angle =45, hjust = 1),
axis.text.y=element_text(colour="black", size = 14),
legend.position = "none",
text = element_text(family = "Calibri"))
This is showing mean consumption rates of mackerels for different prey groups这显示了不同猎物群体的鲭鱼平均消费率
But what I really want is something like但我真正想要的是
Only lower borders should be kept只应保留下边界
or even costumize so I only keep lower border of main titles.甚至装扮,所以我只保留主要标题的下边框。
For removing the boxes around the strips, you can set strip.background = element_blank()
.要删除条带周围的框,您可以设置
strip.background = element_blank()
。 For underlining the strips that span multiple smaller ones, you can set nest_line = element_line()
.要为跨越多个较小的条带下划线,您可以设置
nest_line = element_line()
。
Simplified example below:下面的简化示例:
library(ggh4x)
#> Loading required package: ggplot2
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
facet_nested(~ vs + cyl, nest_line = element_line()) +
theme(strip.background = element_blank())
Created on 2022-01-05 by the reprex package (v2.0.1)由代表 package (v2.0.1) 于 2022 年 1 月 5 日创建
EDIT:编辑:
If you want to underline the strip of every top layer, regardless of whether it spans multiple ones below, you can use element_part_rect()
for the top layer as follows:如果要为每个顶层的条带下划线,无论它是否跨越下面的多个,都可以对顶层使用
element_part_rect()
,如下所示:
library(ggh4x)
#> Loading required package: ggplot2
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
geom_point(
data = data.frame(vs = "dummy", cyl = "dummy", mpg = 20, wt = 3)
) +
facet_nested(
~ vs + cyl,
strip = strip_nested(
background_x = list(
element_part_rect(side = "b", fill = NA, colour = "black"),
element_rect(colour = NA, fill = NA) # repeat this line for every layer that shouldn't be underlined
),
by_layer_x = TRUE, clip = "off"
)
)
Created on 2022-01-06 by the reprex package (v2.0.1)由代表 package (v2.0.1) 于 2022 年 1 月 6 日创建
More info on customising the theming of strips here .有关在此处自定义条带主题的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.