gpt4 book ai didi

r - 将ggplot2网格导出为PDF错误: 'Error in grid.Call.graphics... invalid font type'

转载 作者:行者123 更新时间:2023-12-01 16:08:43 30 4
gpt4 key购买 nike

我想知道你们是否遇到过以下问题:当我尝试使用以下代码将绘图导出为 PDF 以保留透明度时:

    f <- function(x) {
ans <- boxplot.stats(x)
data.frame(ymin = ans$conf[1], ymax = ans$conf[2], y = ans$stats[3])
}

RTs.box = ggplot(mean.vis.aud.long, aes(x = Report, y = RTs, fill = Report)) + theme_bw() + facet_grid(Audio~Visual)
RTs.box +

geom_boxplot(outlier.shape=1 ) + geom_hline(yintercept = .333, linetype = 3, alpha = .8) + theme(legend.position = "none") + ylab("Reposponse Times ms") + scale_fill_grey(start=.4) +
labs(title = expression("Visual Condition")) + theme(plot.title = element_text(size = rel(1)))+
theme(panel.background = element_rect(fill = "grey90"), panel.grid.minor = element_blank())+ stat_summary(fun.data = f, geom = "crossbar",
colour = NA, fill = "white", width = 0.75, alpha = .9)+
geom_boxplot(fill = "transparent", outlier.shape=1)+
theme(axis.title.y = element_text(vjust=0.5)) +
theme(axis.title.x = element_text(vjust=-0.5)) +
theme(text=element_text(size=30))+
theme(axis.title.x=element_text(size=40))+
theme(axis.title.y=element_text(size=40))+
theme(plot.title = element_text(size = 40, vjust=1))+ #vjust respositions text
coord_cartesian(ylim = c(0, 3000))+# This allows clipping of plot without dicarding data in analysis
scale_y_continuous(breaks = (seq(0,3000,by = 500)))+
theme(axis.text.y =element_text(size=17, (hjust=-.5)))+ # THIS CHANGES SIZE OF VALUES ON Y-AXIS
theme(panel.margin = unit(1.2, "lines"))# moves panels further apart

我收到以下错误:

enter image description here

“grid.Call.graphics 中出现错误...无效的字体类型”

图像确实保存为 PDF,但所有轴文本尚未保存。

我尝试导入库(extrafont),但无论我使用什么字体,都会出现相同的错误。

你们中有人以前遇到过这个问题和/或您对如何解决这个问题有什么建议吗?

一如既往地感谢。

编辑:

以下是mean.vis.long 的一些示例数据:

Visual              Audio            Report  subject_nr    RTs
Right Circle 1st 2 Central Beeps Right 10 717.6936
Right Circle 1st Left Beep 1st Left 10 540.0408
Right Circle 1st 1 Central Beep SIM 10 540.0408
Right Circle 1st No Beep Right 10 717.6936
Right Circle 1st Right Beep 1st Left 10 540.0408
Right Circle 1st Left Beep 1st SIM 10 540.0408
Left Circle 1st 2 Central Beeps Right 10 717.6936
Left Circle 1st Left Beep 1st Left 10 540.0408
Left Circle 1st 1 Central Beep SIM 10 540.0408
Left Circle 1st No Beep Right 10 717.6936
Left Circle 1st Right Beep 1st Left 10 540.0408
Left Circle 1st Left Beep 1st SIM 10 540.0408
Left Circle 1st 2 Central Beeps Right 10 717.6936
SIM Circle Pres Left Beep 1st Left 10 540.0408
SIM Circle Pres 1 Central Beep SIM 10 540.0408
SIM Circle Pres No Beep Right 10 717.6936
SIM Circle Pres Right Beep 1st Left 10 540.0408
SIM Circle Pres Left Beep 1st SIM 10 540.0408

有3种视觉条件:右圈第一;左圈第一个 SIM 卡圈演示。

有 5 种音频条件:1 中央蜂鸣声; 2 声中央蜂鸣声;左蜂鸣声第一声;右蜂鸣声第一声;没有蜂鸣声。

有 3 个报告选项:左;正确的; SIM 卡。

最佳答案

该问题似乎是由 axis.title.x 的多次覆盖(使用 vjustsize)引起的。我重新格式化了代码并进行了一些清理,现在它可以正常工作了。

RTs.box <-  
ggplot(mean.vis.aud.long, aes(x = Report, y = RTs, fill = Report)) +
geom_boxplot(outlier.shape=1 ) +
geom_hline(yintercept = .333, linetype = 3, alpha = .8) +
stat_summary(fun.data = f, geom = "crossbar",
colour = NA, fill = "white", width = 0.75, alpha = .9) +
facet_grid(Audio~Visual) +
scale_fill_grey(start = .4) +
scale_y_continuous(breaks = (seq(0,3000,by = 500))) +
ylab("Reposponse Times ms") +
ggtitle("Visual Condition")

RTs.box +
theme_bw() +
theme(legend.position = "none") +
theme(plot.title = element_text(size = rel(1))) +
theme(panel.background = element_rect(fill = "grey90"),
panel.grid.minor = element_blank()) +
theme(panel.margin = unit(1.2, "lines")) +
theme(text = element_text(size=30)) +
theme(axis.title.y = element_text(size=40, vjust=0.5)) +
theme(axis.title.x = element_text(size=40, vjust=-0.5)) +
theme(plot.title = element_text(size=40, vjust=1)) +
theme(axis.text.y = element_text(size=17, hjust=-.5))

关于r - 将ggplot2网格导出为PDF错误: 'Error in grid.Call.graphics... invalid font type' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31327012/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com