簡體   English   中英

facets 和 facet_grid 一樣,axis.line 和 facet_wrap 一樣?

[英]facets as in facet_grid, and axis.line as for facet_wrap?

我正在嘗試使用 facets 構建一個繪圖,如 ,因此使用兩個因素在 x 和 y 軸上分開繪圖,如下所示:

mtcars %>% ggplot() +
  geom_point(aes(x=mpg, y=wt)) + 
  facet_grid(cyl ~ gear, scales="free") + 
  theme(panel.background = element_blank(), axis.line = element_line(size=0.5))

在此處輸入圖片說明

上述方法的問題是只顯示了最上圖和最左圖的軸線,因此在不使用彩色panel.background情況下很難區分圖。

不會出現此問題,但此函數顯然不會對兩個軸中的因素進行分組,或者條帶將始終位於一側(根據strip.position參數),但不會向上和向右facet_grid 例如:

mtcars %>% ggplot() + 
  geom_point(aes(x=mpg, y=wt)) +
  facet_wrap(cyl ~ gear, scales="free") + 
  theme(panel.background = element_blank(), axis.line = element_line(size=0.5))

在此處輸入圖片說明

問題是否可以使用facet_grid創建繪圖,但在所有軸上都有線條,或者使用facet_wrap ,但與facet_grid一樣對因子進行facet_grid

我認為您正在lemon包中尋找facet_rep_grid 這是生成所需圖的代碼。

library(tidyverse)
library(lemon)

mtcars %>% ggplot() + 
  geom_point(aes(x=mpg, 
                 y=wt)) + 
  facet_rep_grid(cyl ~ gear, 
                 scales="free",
                 repeat.tick.labels = "all") + 
  theme(panel.background = element_blank(), 
        axis.line = element_line(size=0.5))

情節檸檬代表

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM