plotting 3-way interaction with ggeffects, theme changes not being applied to all facets

I’m using the plot and predict functions from ggeffects to plot a 3-way interaction. The plots are being generated, but when I try to apply theme changes they only get applied to the second facet, see below

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>library(ggeffects)
library(ggplot2)
dat_iris <- iris
dat_iris$Petal.Size <- ifelse(dat_iris$Petal.Length <= 3, "small", "big")
model_iris <- glm(Sepal.Length ~ Sepal.Width*Species + Petal.Width + Petal.Size, data = dat_iris)
gg_iris <- plot(ggpredict(model_iris, terms=c("Sepal.Width", "Species", "Petal.Width", "Petal.Size")), colors = c("#190C3EFF", "#9C2964FF", "#F8870EFF"))
gg_iris
gg_iris +
xlab("Sepal Width") +
ylab("Sepal Length") +
guides(color = guide_legend("Species"), fill = guide_legend("Species")) +
theme_minimal() +
theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3),
panel.background = element_rect(fill = "white", color = NA),
plot.title = element_blank(),
legend.title = element_text(face = "bold", size = 9),
legend.text = element_text(size = 9),
legend.position = "right",
axis.title.x = element_text(face = "bold", size = 9),
axis.title.y = element_text(face="bold", size = 9),
strip.background = element_rect(fill = "#F0F0F0", color = NA),
strip.text = element_text(face = "bold", size = 9)) +
scale_y_continuous(breaks = 4:8) +
scale_x_continuous(breaks = 2:5)
</code>
<code>library(ggeffects) library(ggplot2) dat_iris <- iris dat_iris$Petal.Size <- ifelse(dat_iris$Petal.Length <= 3, "small", "big") model_iris <- glm(Sepal.Length ~ Sepal.Width*Species + Petal.Width + Petal.Size, data = dat_iris) gg_iris <- plot(ggpredict(model_iris, terms=c("Sepal.Width", "Species", "Petal.Width", "Petal.Size")), colors = c("#190C3EFF", "#9C2964FF", "#F8870EFF")) gg_iris gg_iris + xlab("Sepal Width") + ylab("Sepal Length") + guides(color = guide_legend("Species"), fill = guide_legend("Species")) + theme_minimal() + theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3), panel.background = element_rect(fill = "white", color = NA), plot.title = element_blank(), legend.title = element_text(face = "bold", size = 9), legend.text = element_text(size = 9), legend.position = "right", axis.title.x = element_text(face = "bold", size = 9), axis.title.y = element_text(face="bold", size = 9), strip.background = element_rect(fill = "#F0F0F0", color = NA), strip.text = element_text(face = "bold", size = 9)) + scale_y_continuous(breaks = 4:8) + scale_x_continuous(breaks = 2:5) </code>
library(ggeffects)
library(ggplot2)

dat_iris <- iris

dat_iris$Petal.Size <- ifelse(dat_iris$Petal.Length <= 3, "small", "big")

model_iris <- glm(Sepal.Length ~ Sepal.Width*Species + Petal.Width + Petal.Size, data = dat_iris)

gg_iris <- plot(ggpredict(model_iris, terms=c("Sepal.Width", "Species", "Petal.Width", "Petal.Size")),  colors = c("#190C3EFF", "#9C2964FF", "#F8870EFF"))

gg_iris

gg_iris +
  xlab("Sepal Width") +
  ylab("Sepal Length") +
  guides(color = guide_legend("Species"), fill = guide_legend("Species")) +
  theme_minimal() +
  theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3),
        panel.background = element_rect(fill = "white", color = NA),
        plot.title = element_blank(),
        legend.title = element_text(face = "bold", size = 9),
        legend.text = element_text(size = 9),
        legend.position = "right",
        axis.title.x = element_text(face = "bold", size = 9), 
        axis.title.y = element_text(face="bold", size = 9),
        strip.background = element_rect(fill = "#F0F0F0", color = NA),
        strip.text = element_text(face = "bold", size = 9)) +
  scale_y_continuous(breaks = 4:8) +
  scale_x_continuous(breaks = 2:5)

The resulting image looks like this:

I have read the ggeffects documentation, which states that “Load library(ggplot2) and use theme_set(theme_ggeffects()) to set the ggeffects-theme as default plotting theme. You can then use further plot-modifiers, e.g. from sjPlot, like legend_style() or font_size() without losing the theme-modifications.” However this is does not seem to work with normal ggplot2 theme adjustments. Even following the documentation here https://strengejacke.github.io/ggeffects/articles/ggeffects.html, theme changes only get applied to one facet

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>gg_iris + theme(legend.position = "bottom")
</code>
<code>gg_iris + theme(legend.position = "bottom") </code>
gg_iris + theme(legend.position = "bottom")

I also tried manually faceting like this plot(ggpredict(model_iris, terms=c("Sepal.Width", "Species", "Petal.Width")), colors = c("#190C3EFF", "#9C2964FF", "#F8870EFF")) + facet_wrap(~"Petal.Size") but this resulted in super bizarre output.

Is there a way to get the theme changes applied to all facets?

ggeffects uses patchwork to arrange the plots (facets are used within each of the two main panels), so you can apply themes and scales in the way you would to a patchwork object.

That is, use & instead of + to apply themes and scales to all the plots in the arrangement, and plot_layout(guides="collect") to use the same legend for all plots.

So:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>gg_iris +
plot_layout(guides="collect") &
xlab("Sepal Width") &
ylab("Sepal Length") &
scale_y_continuous(breaks = 4:8) &
scale_x_continuous(breaks = 2:5) &
guides(color = guide_legend("Species"), fill = guide_legend("Species")) &
theme_minimal() &
theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3),
panel.background = element_rect(fill = "white", color = NA),
plot.title = element_blank(),
legend.title = element_text(face = "bold", size = 9),
legend.text = element_text(size = 9),
legend.position = "bottom",
axis.title.x = element_text(face = "bold", size = 9),
axis.title.y = element_text(face="bold", size = 9),
strip.background = element_rect(fill = "#F0F0F0", color = NA),
strip.text = element_text(face = "bold", size = 9))
</code>
<code>gg_iris + plot_layout(guides="collect") & xlab("Sepal Width") & ylab("Sepal Length") & scale_y_continuous(breaks = 4:8) & scale_x_continuous(breaks = 2:5) & guides(color = guide_legend("Species"), fill = guide_legend("Species")) & theme_minimal() & theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3), panel.background = element_rect(fill = "white", color = NA), plot.title = element_blank(), legend.title = element_text(face = "bold", size = 9), legend.text = element_text(size = 9), legend.position = "bottom", axis.title.x = element_text(face = "bold", size = 9), axis.title.y = element_text(face="bold", size = 9), strip.background = element_rect(fill = "#F0F0F0", color = NA), strip.text = element_text(face = "bold", size = 9)) </code>
gg_iris +
  plot_layout(guides="collect") &
  xlab("Sepal Width") &
  ylab("Sepal Length") &
  scale_y_continuous(breaks = 4:8) &
  scale_x_continuous(breaks = 2:5) & 
  guides(color = guide_legend("Species"), fill = guide_legend("Species")) &
  theme_minimal() &
  theme(panel.grid.major = element_line(color = "#E5E5E5", linetype = "dashed", linewidth = 0.3),
        panel.background = element_rect(fill = "white", color = NA),
        plot.title = element_blank(),
        legend.title = element_text(face = "bold", size = 9),
        legend.text = element_text(size = 9),
        legend.position = "bottom",
        axis.title.x = element_text(face = "bold", size = 9), 
        axis.title.y = element_text(face="bold", size = 9),
        strip.background = element_rect(fill = "#F0F0F0", color = NA),
        strip.text = element_text(face = "bold", size = 9))

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật