1

所以我得到了帮助来改变我图表上不同方面的比例。建议使用下面的代码,但现在我无法将标签和轴刻度的字体设置为粗体。在我使用的旧代码中

theme(
     axis.text.x = element_text(size = 12,face="bold"),#, angle = 10, hjust = .5, vjust = .5),axis.text.y = element_text(size = 12, face = "bold"),
     axis.title.y = element_text(vjust= 1.8, size = 16),
     axis.title.x = element_text(vjust= -0.5, size = 16),
     axis.title = element_text(face = "bold"))

但它不起作用。

tgc <- structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L), .Label = c("Visible", "Remembered"), class = "factor"), 
    Condition = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 
    3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L
    ), .Label = c("CEN", "IPS", "CTL"), class = "factor"), test = structure(c(1L, 
    1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 
    1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("Pre-test", "Post-test"
    ), class = "factor"), Session = structure(c(1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L, 1L, 2L, 1L, 2L), .Label = c("Adaptation", "Post-adaptation"
    ), class = "factor"), N = c(12, 12, 12, 12, 12, 12, 12, 12, 
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
    12), EE = c(2.134379625, 0.333942625, 1.742841125, 0.317361916666667, 
    2.84197270833333, 0.307057416666667, 2.403112375, 0.281202, 
    3.49590529166667, 0.305657666666667, 2.85211466666667, 0.3131155, 
    1.44857545833333, 0.269328166666667, 1.740270875, 0.243361833333333, 
    2.10702266666667, 0.286209125, 2.145855125, 0.305474083333333, 
    1.60016616666667, 0.281528625, 1.94182179166667, 0.294655916666667
    ), sd = c(0.727246182828044, 0.0816168443914292, 0.549168068103643, 
    0.0894916121701392, 1.14554677132408, 0.0958562360654162, 
    1.06827971273128, 0.0953131237162305, 1.18204258551111, 0.0896670491921828, 
    1.32864473484909, 0.109865886496798, 0.605344957514288, 0.0815454655757737, 
    0.833908172662699, 0.0798994165789182, 1.11582277105041, 
    0.0976064300150272, 0.667812406644538, 0.142929179817685, 
    0.686043669971901, 0.109794818975944, 1.39509308576833, 0.161854932615856
    ), se = c(0.209937889711449, 0.0235607535398997, 0.158531165974993, 
    0.0258340031883217, 0.330690868396632, 0.0276713118479362, 
    0.308385789857611, 0.0275145288174349, 0.341226302469221, 
    0.0258846474942731, 0.383546697661249, 0.0317155495718416, 
    0.174748037086728, 0.0235401482506832, 0.240728553983119, 
    0.0230649748349663, 0.322110288616933, 0.0281765493219072, 
    0.192780836372198, 0.0412601002213964, 0.198043748767058, 
    0.0316950341456936, 0.402728684306467, 0.0467234944577166
    ), ci = c(0.462070179795855, 0.0518568689018959, 0.348924743722983, 
    0.0568602576432562, 0.727845693918804, 0.0609041467375754, 
    0.678752547059741, 0.0605590696140879, 0.751034027967696, 
    0.0569717250090983, 0.844180589754564, 0.069805453951774, 
    0.384617836383033, 0.0518115169661108, 0.529839974927164, 
    0.0507656673296478, 0.708959965158704, 0.0620161669201078, 
    0.424307760005262, 0.0908128682911871, 0.435891352085212, 
    0.0697602998032695, 0.886399857701764, 0.102837717929058)), row.names = c(NA, 
-24L), class = "data.frame")
ls_p <- 
   tgc %>%
   split(., .$Session) %>%
   map(function(x){
     ggplot(x, aes(x = Condition, y = EE, fill = test)) +
       geom_errorbar(aes(ymin = EE - se, ymax = EE + se, group = test), position = position_dodge(0.5), width = .1) +
       geom_col(width = 0.5, color = "black", position = "dodge") +
       labs(x= "Workspace", y = "EE (cm)") +
       scale_fill_manual("Test:", values = c("grey80", "grey20")) +
       facet_nested(. ~ Session + Group, scales = "free_y") +
       cowplot::theme_half_open() 
   })
 
 wrap_plots(ls_p) + plot_layout(guides = "collect") & 
   theme(legend.position = "bottom", legend.margin=margin(t=0, r=3, b=5, l=3, unit="cm")) + theme(aspect.ratio = 3/2) 
 
4

2 回答 2

0

调用拼凑主题时有两种选择。您可以在绘图级别(使用+)或拼凑级别(使用&)执行此操作。下面只是一种同时使用这两个选项的方法,用于演示目的。

为什么你应该theme()只调用一次?

多次调用主题在技术上并没有错,但它会使代码混乱。为什么这么糟糕?您很容易创建错误/错误,因为很容易创建相互矛盾的主题调用。

library(tidyverse)
library(ggh4x)
library(patchwork)

ls_p <- 
  tgc %>%
  split(., .$Session) %>%
  map(function(x){
    ggplot(x, aes(x = Condition, y = EE, fill = test)) +
      geom_errorbar(aes(ymin = EE - se, ymax = EE + se, group = test), position = position_dodge(0.5), width = .1) +
      geom_col(width = 0.5, color = "black", position = "dodge") +
      labs(x= "Workspace", y = "EE (cm)") +
      scale_fill_manual("Test:", values = c("grey80", "grey20")) +
      facet_nested(. ~ Session + Group, scales = "free_y") +
      cowplot::theme_half_open() +
      theme(axis.text.x = element_text(size = 12,face="bold"),#, angle = 10, hjust = .5, vjust = .5),axis.text.y = element_text(size = 12, face = "bold"),
            axis.title.y = element_text(vjust= 1.8, size = 16),
            axis.title.x = element_text(vjust= -0.5, size = 16),
            axis.title = element_text(face = "bold"))
  })

wrap_plots(ls_p) + plot_layout(guides = "collect") & 
  theme(legend.position = "bottom",
        aspect.ratio = 3/2)

于 2021-11-11T08:04:11.893 回答
0

有用。我认为您错过了添加theme内容的订单/位置。

wrap_plots(ls_p) + plot_layout(guides = "collect") & 
  theme(legend.position = "bottom", legend.margin=margin(t=0, r=3, b=5, l=3, unit="cm")) + theme(aspect.ratio = 3/2) +
  theme(
    axis.text.x = element_text(size = 12,face="bold"),#, angle = 10, hjust = .5, vjust = .5),axis.text.y = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 16),
    axis.title.x = element_text(vjust= -0.5, size = 16),
    axis.title = element_text(face = "bold"))

在此处输入图像描述

theme无物情节

在此处输入图像描述

于 2021-11-11T01:43:33.360 回答