-
Notifications
You must be signed in to change notification settings - Fork 0
/
Readme.Rmd
executable file
·61 lines (47 loc) · 1.84 KB
/
Readme.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: "Readme"
author: "Anton Könneke"
date: "2023-06-01"
output: github_document
---
This repository stores some helper functions that I use.
# Save ggplot as tikz
This is handy for exporting ggplots to LaTeX with the `ggsave` framework and `last_plot`.
The function builds on the approach outlined by [Ilyass Tabiai](https://github.com/ilyasst) in this [blog post](http://iltabiai.github.io/tips/latex/2015/09/15/latex-tikzdevice-r.html). The main part is done by the
package [tikzDevice](https://github.com/daqana/tikzDevice) by Charlie Sharpsteen et al.
```{r}
library(ggplot2)
library(tikzDevice)
source("ggtiksave.R")
ggplot(mpg)+
geom_point(aes(displ, cty, color = drv))+
theme_minimal()+
xlab("Look, greek letters $\\alpha \\beta \\Gamma \\Phi$")+
ylab("And Math! $\\frac{20}{19} \\prod_{k=1}^n$ ")+
ggtitle("Wait, is this \\LaTeX?")
ggtiksave("myplot.tex")
```
And this is the result if `myplot.tex` is `input` into a tex doc (with tikz loaded!).
![Latin Modern](latex_screenshot.png)
The neat thing is that now, whenever the font of the \Latex file is changed, so
is the font in the plot:
## Palatino Font
![Palatino font](font1.png)
## Linux Libertine Font
![Libertine font](font2.png)
# Encode Excel columns
Quite frequently when working with human generated excel files,
spaces are accidentially stored in numeric cells. In addition to that, it is
common to use `,`instead of `.` as decimal markers in germany. As neither
`readxl::read_xlsx` nor `openxlsx::read.xlsx` seem able to account for this, this little function
does the correction afterwards. By wrapping it in `mutate(across())` call, the job can be easily done.
```{r message=FALSE}
source("fix_excel_numcols.R")
require(dplyr)
df <- tibble(
A = c("1,3", "1,5 ", "2"),
B = c("1,1", "5,5 ", " 2,4")
)
df %>%
mutate(across(everything(), ~fix_excel_numcols(.x)))
```