使用force_panelsizes tovenage gghx4之后重置面板问题

发布于 2025-02-03 23:48:02 字数 3690 浏览 3 评论 0 原文

使用force_panelsize gghx4的force_panelsize之后,如何重置绘图面板?由于我已经在ggplot上使用了此功能(并且决定不使用它),我的绘图面板似乎被此功能引起的设置所困扰。

例如,我的情节以前和现在看起来像这样(由于隐私原因,我必须模糊一些数据):

之前

<

a href =“ https://i.sstatic.net/c2omd。 png“ rel =” nofollow noreferrer“> ”

因此,第一个绘图几乎使用了整个页面,第二个仍然受宽度和高度的限制。

我已经重新安装了我的R版本(4.1.0),R Studio版本(2022.02.3),GGPLOT2和Tinytex的乳胶版本。这些地块是针织报告的一部分。由于隐私原因,我不得不模糊某些部分。

A MRE 我正在使用的代码的示例(由于隐私原因而更改数据的最小变化,并且由于绘图区域很小而使用的标题,标题和X轴的使用边距最小的更改 - 否则不会绘制任何条形):

---
output:
  pdf_document:
    number_sections: true
classoption: a4paper
geometry: left=2cm,right=1cm,top=1.5cm,bottom=1cm,includeheadfoot
fontsize: 11pt
lang: de
header-includes:
-   \usepackage{caption}
-   \captionsetup[figure]{font={footnotesize,rm}}
-   \captionsetup[table]{font={footnotesize,rm}}
-   \usepackage{lastpage}
-   \usepackage{fancyhdr}
-   \pagestyle{fancy}
-   \fancyhf{}
-   \fancyhead[R]{\fontsize{9}{11} \selectfont \leftmark}
-   \fancyhead[L]{\fontsize{9}{11} \selectfont Spezialauswertung}
-   \fancyfoot[R]{\fontsize{9}{0} \selectfont Seite \thepage\ von \pageref{LastPage}}
---

```{r echo=FALSE, warning=FALSE}
library(ggplot2)

df <- data.frame(cbind(
    Pop=rep(1:3,8),
    Question_Cat=rep(1:8,each=3),
    Values=c(84,89,100,92,100,10,82,91,100,26,18,26,76,90,77,52,36,50,83,100,100,72,81,73),
    n=c(129,11,19,90,11,19,101,11,19,127,11,19,126,11,18,120,11,7,127,11,19,125,11,19),
    sort=rep(1:8,each=3))
  )

lab <- c("Question 1","Question 2","Question 3","Question 4","Question 5","Question 6","Question 7","Question 8")
names(lab) <- as.character(1:8)


ggplot(data=df,aes(x=1,y=Values)) +
  geom_bar(aes(group=Pop,fill=factor(Pop)),stat="identity",position="dodge") +
  facet_wrap(~ sort,nrow=8,labeller=labeller(.default=lab,.multi_line = FALSE)) +
  scale_fill_manual(values=c("#5ba755","#ddebf7","#acb9ca"),labels=c("Group 1","Group 2","Group 3")) +
  coord_flip() +
  ylim(-2,100) +
  geom_text(aes(label=paste(round(Values,2),"%"),group=Pop),position = position_dodge(0.9),hjust=-0.4,vjust=0.35,size=rel(2)) +
  geom_text(aes(label=paste("n=",n),y=0,group=Pop),position = position_dodge(0.9),hjust=1.2,size=rel(2)) +
  theme_classic() +    
      theme(legend.position = "top", legend.title = element_blank(),legend.text=element_text(size=rel(0.6)),
        plot.title = element_text(hjust = 0.5,size=rel(1.1),face="bold",margin=margin(25,0,5,0)),
        plot.caption.position="plot",plot.caption = element_text(size=rel(0.7),margin=margin(0,0,0,0)),
        strip.text.x = element_text(size=rel(0.8),face="italic",hjust=0),
        strip.background = element_blank(),
        axis.text.y=element_blank(),
        axis.line.y=element_blank(),
        axis.ticks.y=element_blank(),axis.title.y=element_blank(),
        axis.title.x=element_text(size=rel(0.7),margin=margin(0,0,0,0)),
        axis.text.x=element_text(size=rel(0.85),margin=margin(0,0,0,0))) +
  guides(fill = guide_legend(reverse = TRUE)) +
  ylab("Prozent") +
  xlab("") +
  labs(title="Some Plot Title here",subtitle="",caption = "Some explanation here")

```

PDF输出看起来像这样(仍然是错误的):

“在此处输入图像说明”

在所有3个输出标题中均未显示。

我还尝试使用dev.off()关闭绘图面板,但只剩下空设备: dev.off()中的错误:无法关闭设备1(NULL设备)

对出了什么问题的想法?

任何帮助都非常感谢:)))))))))))))))

谢谢!

How can I reset my plot panel after using force_panelsizes of package gghx4 ? Since I have used this function on a ggplot (and decided not to use it) my plotting panel seems to be stuck with the setup caused by this function.

My plots look for example like this before and now (I had to blur some data due to privacy reasons):

BEFORE

enter image description here

AFTER

enter image description here

So the first plot uses almost the whole page, the second is still limited by width and height.

I already reinstalled my R version (4.1.0), R Studio version (2022.02.3), ggplot2 and my latex-version of tinytex. The plots are part of a knitted report. I had to blur some parts due to privacy reasons.

A MRE Example of the code I'm using (with minimal change in data for privacy reasons and minimal changes in the used margins for the title, caption and x-Axis because of the small plot area - otherwise no bars would have been plotted):

---
output:
  pdf_document:
    number_sections: true
classoption: a4paper
geometry: left=2cm,right=1cm,top=1.5cm,bottom=1cm,includeheadfoot
fontsize: 11pt
lang: de
header-includes:
-   \usepackage{caption}
-   \captionsetup[figure]{font={footnotesize,rm}}
-   \captionsetup[table]{font={footnotesize,rm}}
-   \usepackage{lastpage}
-   \usepackage{fancyhdr}
-   \pagestyle{fancy}
-   \fancyhf{}
-   \fancyhead[R]{\fontsize{9}{11} \selectfont \leftmark}
-   \fancyhead[L]{\fontsize{9}{11} \selectfont Spezialauswertung}
-   \fancyfoot[R]{\fontsize{9}{0} \selectfont Seite \thepage\ von \pageref{LastPage}}
---

```{r echo=FALSE, warning=FALSE}
library(ggplot2)

df <- data.frame(cbind(
    Pop=rep(1:3,8),
    Question_Cat=rep(1:8,each=3),
    Values=c(84,89,100,92,100,10,82,91,100,26,18,26,76,90,77,52,36,50,83,100,100,72,81,73),
    n=c(129,11,19,90,11,19,101,11,19,127,11,19,126,11,18,120,11,7,127,11,19,125,11,19),
    sort=rep(1:8,each=3))
  )

lab <- c("Question 1","Question 2","Question 3","Question 4","Question 5","Question 6","Question 7","Question 8")
names(lab) <- as.character(1:8)


ggplot(data=df,aes(x=1,y=Values)) +
  geom_bar(aes(group=Pop,fill=factor(Pop)),stat="identity",position="dodge") +
  facet_wrap(~ sort,nrow=8,labeller=labeller(.default=lab,.multi_line = FALSE)) +
  scale_fill_manual(values=c("#5ba755","#ddebf7","#acb9ca"),labels=c("Group 1","Group 2","Group 3")) +
  coord_flip() +
  ylim(-2,100) +
  geom_text(aes(label=paste(round(Values,2),"%"),group=Pop),position = position_dodge(0.9),hjust=-0.4,vjust=0.35,size=rel(2)) +
  geom_text(aes(label=paste("n=",n),y=0,group=Pop),position = position_dodge(0.9),hjust=1.2,size=rel(2)) +
  theme_classic() +    
      theme(legend.position = "top", legend.title = element_blank(),legend.text=element_text(size=rel(0.6)),
        plot.title = element_text(hjust = 0.5,size=rel(1.1),face="bold",margin=margin(25,0,5,0)),
        plot.caption.position="plot",plot.caption = element_text(size=rel(0.7),margin=margin(0,0,0,0)),
        strip.text.x = element_text(size=rel(0.8),face="italic",hjust=0),
        strip.background = element_blank(),
        axis.text.y=element_blank(),
        axis.line.y=element_blank(),
        axis.ticks.y=element_blank(),axis.title.y=element_blank(),
        axis.title.x=element_text(size=rel(0.7),margin=margin(0,0,0,0)),
        axis.text.x=element_text(size=rel(0.85),margin=margin(0,0,0,0))) +
  guides(fill = guide_legend(reverse = TRUE)) +
  ylab("Prozent") +
  xlab("") +
  labs(title="Some Plot Title here",subtitle="",caption = "Some explanation here")

```

The PDF-Output looks like this (still wrong):

enter image description here

In all 3 outputs header and footer are not shown.

I also tried to close the plotting panels with dev.off() but there is only the NULL device left:
Error in dev.off() : cannot shut down device 1 (the null device)

Any ideas of what went wrong?

Any help is really appreciated :))))))))))))))))

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文