我正在嘗試制作可發布的圖形,其中一個圖形的底軸(帶有刻度線)與它下面的圖形的頂軸干凈地結合在一起。以下是它的外觀示例,盡管此示例在每個面板上都沒有刻度線:

這是我的嘗試,只需使用 grid.arrange:
#Libraries:
library(ggplot2)
library(dplyr)
library(gridExtra)
#Filter to create two separate data sets:
dna1 <- DNase %>% filter(Run == 1)
dna2 <- DNase %>% filter(Run == 2)
#Figure 1:
dna1_plot <- ggplot(dna1, aes(x = conc, y = density)) geom_point() theme_classic()
theme(axis.title.x = element_blank())
#Figure 2:
dna2_plot <- ggplot(dna2, aes(x = conc, y = density)) geom_point() theme_classic()
#Using grid.arrange to combine:
dna <- grid.arrange(dna1_plot, dna2_plot, nrow = 2)

并嘗試對情節邊距進行一些調整,盡管這似乎不起作用:
dna1_plot_round2 <- ggplot(dna1, aes(x = conc, y = density)) geom_point() theme_classic()
theme(axis.title.x = element_blank(),
plot.margin = (0,0,0,0), "cm")
dna2_plot_round2 <- ggplot(dna2, aes(x = conc, y = density)) geom_point() theme_classic()
theme(plot.margin = unit(c(-0.5,-1,0,0), "cm"))
dna_round2 <- grid.arrange(dna1_plot_round2, dna2_plot_round2, nrow = 2)

有誰知道在ggplot中堆疊這樣的數字的最佳方法?有沒有比使用 grid.arrange 更好的方法?如果可能的話,最好看看如何在每個 x 軸上使用/不使用刻度線。
謝謝!
uj5u.com熱心網友回復:
你不需要任何非本地的 ggplot 東西。將您的資料保存在一個資料框中并使用facet_grid.
dna <- DNase %>% filter(Run %in% 1:2)
ggplot(dna, aes(x = conc, y = density))
geom_point()
theme_bw()
facet_grid(rows = vars(Run))
theme(panel.spacing = unit(0, "mm"))

uj5u.com熱心網友回復:
R 包
你也可以試試最近的
編輯以更好地解決@Cameron 的問題。
根據
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416777.html
標籤:
上一篇:如何將一系列影像繪制到特定地圖上
下一篇:在R中更改餅圖中切片的順序
