Problem with pdf plot alignment.
With coord_polar()
and theme_void()
there is strange alignmet, even when elements are present that are white
. When adding a geom_hline()
if colour = "white"
then alignment fails, if colour = black
then alignment is successful.
Is a problem when knitting to .pdf
. I have knit to two columns to get it all onto one page for a screenshot, but the problem persists in single column. The same alignment problem happens when a coord_polar()
plot has asymetric labels on one side, with fig.align="center"
the alignment is off.
---
output: pdf_document
classoption:
- twocolumn
---
```{r, echo = FALSE}
knitr::opts_chunk$set(fig.height = 2)
```
```{r, message=FALSE}
library(ggplot2)
## Normal Plot
p1 <- ggplot(diamonds) +
aes(x = carat) +
geom_histogram() +
coord_polar()
p1
## `theme_void()` means strange alignment
p2 <- p1 + theme_void()
p2
## Adding a line fixes alignment
line <- 12000
p3 <- p2 + geom_hline(yintercept = line)
p3
## Adding a white line breaks alignment
p2 + geom_hline(yintercept = line,
colour = "white")
## Adding a white line over a black line fixes alignment
p3 + geom_hline(yintercept = line,
colour = "white",
size = 3)
```
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 htmltools_0.5.1.1 tools_4.0.2 yaml_2.2.1
[5] rmarkdown_2.8 knitr_1.33 xfun_0.23 digest_0.6.27
[9] rlang_0.4.11 evaluate_0.14