我正在寻找两样东西来实现我的数据的良好表现。
throughout.
重排序,便于视觉比较。

下面是我的代码
RI_pH<-data.frame(RI_pH)
RI_pH$Landcover<-factor(RI_pH$Landcover,levels =c("Bare","Vegetation","Mixed"))
RI_pH$Predictor<-factor(RI_pH$Predictor,levels=c("Landsat8","Landsat8 & Sentinel1",
"Sentinel1","All Variables"))
bar<-ggplot(RI_pH,aes(x=Variable,y=RI,fill=Landcover))+
geom_col(width =0.5)+
facet_wrap(~Predictor,scales = "free")+
scale_x_discrete()+
theme(axis.text.x = element_text(angle = 90, hjust=0.95,vjust=0.2, size=32))+
theme(axis.text.y=element_text(size=32))+
theme(strip.text = element text(size=52, face=2))
jpeg(file="bar%03d.jpeg",width=1180,height=849,
pointsize=52,bg="white",units="mm",res=95)
plot(bar)
dev.off()发布于 2022-08-13 16:39:32
获得具有不同面宽的常数列宽的唯一保证是使用facet_grid(scales = "free_x", space = "free_x")拥有一行,因为在ggplot2的内置约束中无法容纳数据的配置(例如,面宽必须从一行对齐到下一行)。
library(ggplot2)
ggplot(mtcars, aes(as.factor(gear), wt, fill = as.factor(cyl))) +
geom_col() +
facet_grid(~carb, scales = "free_x", space = "free_x")

如果您想要一个更自定义的布局,您可能需要依赖像patchwork这样的包来帮助您组合绘图,但是我想不出一种简单的方法来保持列宽在行之间对齐。
library(patchwork)
a <- ggplot(subset(mtcars, carb <=3),
aes(as.factor(gear), wt, fill = as.factor(am))) +
geom_col() +
facet_grid(~carb, scales = "free_x", space = "free_x")
b <- ggplot(subset(mtcars, carb > 3),
aes(as.factor(gear), wt, fill = as.factor(am))) +
geom_col() +
facet_grid(~carb, scales = "free_x", space = "free_x")
(a / b) + plot_layout(guides = "collect")

https://stackoverflow.com/questions/73344506
复制相似问题