簡體   English   中英

如何為 R 中的 facet_grid 中的每個構面單獨更改每個圖形的 x 軸中斷數?

[英]How can I change the number of breaks of x axis for each graph individually for each facet in a facet_grid in R?

如何為 facet_grid 中的每個構面單獨更改每個圖形的 x 軸中斷數? 我想為每個方面分別修改 x 軸。 我試過 scale_x_continuos(breaks =..., n.breaks = ...) 但我不能。 我還使用 theme_replace 刪除了 theme_set(theme_paleo(8)) 並嘗試使用 theme(axis.x.text =, axis.ticks =, etc etc) 但沒有積極的結果,請任何可以幫助我的人。

這是此鏈接中地層圖的示例: https ://cran.r-project.org/web/packages/tidypaleo/vignettes/strat_diagrams.html

代碼:

library(tidyverse)
library(tidypaleo)
theme_set(theme_paleo(8))

data("alta_lake_geochem")

alta_lake_geochem

alta_plot <- ggplot(alta_lake_geochem, aes(x = value, y = depth)) +
  geom_lineh() +
  geom_point() +
  scale_y_reverse() +
  facet_geochem_gridh(vars(param)) +
  labs(x = NULL, y = "Depth (cm)")

alta_plot

alta_plot

一個選項是ggh4x包,它通過facetted_pos_scales允許為每個方面單獨設置比例。 在下面的代碼中,我使用facetted_pos_scales設置第一個和第三個方面的中斷,而對於所有其他方面,使用默認值 ( NULL )。

注 1: facetted_pos_scales需要通過scales="free_x"釋放 x 比例。

注意 2:為了使facetted_pos_scalesscale_y_reverse一起工作,我也必須將facetted_pos_scales移動到scale_y_reverse內。

library(tidyverse)
library(tidypaleo)
library(ggh4x)

theme_set(theme_paleo(8))

data("alta_lake_geochem")

ggplot(alta_lake_geochem, aes(x = value, y = depth)) +
  geom_lineh() +
  geom_point() +
  facet_geochem_gridh(vars(param), scales = "free_x") +
  labs(x = NULL, y = "Depth (cm)") +
  facetted_pos_scales(
    x = list(
      scale_x_continuous(breaks = 1:8),
      NULL,
      scale_x_continuous(n.breaks = 10),
      NULL
    ),
    y = list(
      scale_y_reverse()
    )
  )

暫無
暫無

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

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