ggplot2中嵌套面中的希腊字母

时间:2019-02-25 13:23:56

标签: r ggplot2 label facet-grid

我有一个巨大的数据集,我需要在x轴(alpha和deid的复制品)和y轴(beta)中具有一个嵌套面的面中进行绘图。

fen_ale_all_rep$alpha <- factor(
  fen_ale_all_rep$alpha,
  levels = c("alpha 0.1", "alpha 0.2", "alpha 0.4", "alpha 0.8", "alpha 1.6"),
  labels = c(
    "alpha '0.1'",
    "alpha '0.2'",
    "alpha '0.4'",
    "alpha '0.8'",
    "alpha '1.6'"
  )
)


fen_ale_rep5$beta <- factor(
  fen_ale_rep5$beta,
  levels = c(
    "beta 0.05",
    "beta 0.1",
    "beta 0.2",
    "beta 0.4",
    "beta 0.8",
    "beta 1.6",
    "beta 3.2",
    "beta 6.4",
    "beta 12.8",
    "beta 25.6",
    "beta 51.2",
    "beta 102.4"
  ),
  labels = c(
    "beta 0.05",
    "beta 0.1",
    "beta 0.2",
    "beta 0.4",
    "beta 0.8",
    "beta 1.6",
    "beta 3.2",
    "beta 6.4",
    "beta 12.8",
    "beta 25.6",
    "beta 51.2",
    "beta 102.4"
  )
)

结构:

tbl <- structure(list(FEN = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                    1L, 1L, 1L, 1L, 1L), .Label = c("Plants", "Insects"), class = "factor"), 
                  NSEL = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                           1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                           1, 1, 1, 1, 1, 1), rep = c("rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", 
                                                      "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1", "rep 1"
                           ), alpha = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                  1L, 1L, 1L, 1L, 1L, 1L), .Label = c("alpha 0.1", "alpha 0.2", 
                                                                                      "alpha 0.4", "alpha 0.8", "alpha 1.6"), class = "factor"), 
                  beta = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                     1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
                                     2L, 2L, 2L, 2L, 2L), .Label = c("beta 0.05", "beta 0.1", 
                                                                     "beta 0.2", "beta 0.4", "beta 0.8", "beta 1.6", "beta 3.2", 
                                                                     "beta 6.4", "beta 12.8", "beta 25.6", "beta 51.2", "beta 102.4"
                                     ), class = "factor"), TEMPO = c(1L, 200L, 400L, 600L, 800L, 
                                                                     1000L, 1200L, 1400L, 1600L, 1800L, 2000L, 2200L, 2400L, 2600L, 
                                                                     2800L, 3000L, 3200L, 3400L, 3600L, 3800L, 4000L, 4200L, 4400L, 
                                                                     4600L, 4800L, 5000L, 5200L, 5400L, 5600L, 5800L, 6000L, 6200L, 
                                                                     6400L, 6600L, 6800L, 7000L, 7200L, 7400L, 7600L, 7800L, 8000L, 
                                                                     8200L, 8400L, 8600L, 8800L, 9000L, 9200L, 9400L, 9600L, 9800L, 
                                                                     10000L, 1L, 200L, 400L, 600L, 800L, 1000L, 1200L, 1400L, 
                                                                     1600L), ab = c("0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", "0.1 0.05", 
                                                                                    "0.1 0.05", "0.1 0.05", "0.1 0.1", "0.1 0.1", "0.1 0.1", 
                                                                                    "0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1", "0.1 0.1"
                                                                     ), especie = c("1", "1", "1", "1", "1", "1", "1", "1", "1", 
                                                                                    "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
                                                                                    "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
                                                                                    "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
                                                                                    "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", 
                                                                                    "1", "1", "1"), trait = c(0.59532188, 0.63023233, 0.59210289, 
                                                                                                              0.58660778, 0.55932657, 0.57032034, 0.56379332, 0.61973847, 
                                                                                                              0.61705717, 0.62310601, 0.61690676, 0.6508817, 0.64581712, 
                                                                                                              0.5890861, 0.66424559, 0.64007846, 0.52734623, 0.65276626, 
                                                                                                              0.57025516, 0.59734711, 0.59672837, 0.57971204, 0.51274562, 
                                                                                                              0.60679023, 0.56463537, 0.64716034, 0.60257023, 0.68582648, 
                                                                                                              0.62075915, 0.46707366, 0.65330306, 0.59301249, 0.70620201, 
                                                                                                              0.5260134, 0.51619464, 0.65620395, 0.48348558, 0.62189428, 
                                                                                                              0.60360017, 0.55274833, 0.56492948, 0.61039593, 0.75225962, 
                                                                                                              0.54349533, 0.47189362, 0.52454647, 0.56282583, 0.63985652, 
                                                                                                              0.58380379, 0.59214658, 0.73188778, 0.62808414, 0.59229323, 
                                                                                                              0.6978987, 0.61346245, 0.49995094, 0.4661158, 0.57436886, 
                                                                                                              0.58524132, 0.60717574)), row.names = c(NA, 60L), class = "data.frame")

我可以制作这个情节:

plot with alpha and beta facets

但是,它不显示复制ID。测试版不遵循新月顺序。

我想要类似的东西

one replicate to each alpha

或一个具有复制和de列且具有每个alpha值(0.1,0.2,....)的单一构面

for(i in 1:10) {
  grid1 <- print(
    ggplot(
      fen_ale_all_rep,
      aes(
        x = TEMPO,
        y = trait,
        group = interaction(FEN, ab, especie, rep),
        colour = FEN
      )
    ) +
      geom_line() +

      labs(x = "Time",
           y = "Mean phenotypes") +
      scale_color_viridis(discrete=TRUE,
        name = NULL
      ) +
      theme_pubclean() + theme(
        axis.text.x = element_text(
          size = 15,
          angle = 0,
          vjust = 0.3
        ),
        axis.text.y = element_text(size = 15),
        plot.title = element_text(size = 15),
        legend.text = element_text(size = 15),
        axis.title.x = element_text(size = 15),
        axis.title.y = element_text(size = 15),
        strip.text.x = element_text(size = 15),
        strip.text.y = element_text(size = 15),
        plot.caption = element_text(size=15),
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), 
        axis.line = element_line(colour = "black"),
        axis.ticks = element_blank(),
        legend.position = "top"
      ) +

      facet_grid_paginate(
        beta ~ alpha+rep,
        ncol = 5,
        nrow = 6,
        page = i, labeller = label_bquote(beta == .(beta), alpha == .(alpha)))))

}

我该如何实现? 提前致谢!对我的英语感到抱歉:)

0 个答案:

没有答案