Created
November 16, 2022 21:57
-
-
Save jthomasmock/293a5a51ea4f536b6548a8abb1a8f04b to your computer and use it in GitHub Desktop.
Rotating images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
format: html | |
--- | |
```{r} | |
library(ggplot2) | |
library(grid) | |
``` | |
```{r} | |
#| warning: false | |
grid::grid.newpage() | |
p <- ggplot(mtcars, aes(x = disp,y = mpg)) + geom_point() | |
print(p, vp=grid::viewport(angle=-90)) | |
``` | |
```{r} | |
#| echo: fenced | |
#| out-extra: "style='transform: rotate(90deg); margin-top: 75px;'" | |
p | |
``` | |
```{r} | |
#| echo: fenced | |
#| out-extra: 'angle=90' | |
p | |
``` | |
```{r} | |
ggsave("norm-plot.png", p) | |
``` | |
Howdy @Haly-en - as far as I know out.extra
and out-extra
are arguments passed to CSS/LaTeX layer - while they may work, it might be dependent on LaTeX packaging?
I am not at all a LaTeX expert, and there may be LaTeX native methods, you may want to reference: https://latex.org/forum/viewtopic.php?t=9323
Or could rotate the image after saving it on disk with magick
:
ggsave("img.png", gg_obj)
library(magick)
plot_img <- image_read("img.png")
# rotate
image_rotate(plot_img, 90)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tom...Thanks for such a quick response.
I am trying to render to a pdf format. I tried all three options, the first one with the grid works to rotate the graph but it doesn't respect the margins or the size of the graph. The last two definitely don't work. :(
I also tried saving the graph and including it as an image... I still can't do it but I keep trying.
`
another example i tried
\newpage
\begin{landscape}
Landscape:
\end{landscape}
`