-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
263 lines (198 loc) · 7.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
---
title: "Delgosha"
output: github_document
---
```{r include=FALSE}
knitr::opts_chunk$set( message=FALSE, warning=FALSE)
library(delgosha)
import_all_fonts()
```
<!-- badges: start -->
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN
status](https://www.r-pkg.org/badges/version/instaloadeR)](https://CRAN.R-project.org/package=instaloadeR)
<!-- badges: end -->
Delgosha is an opinionated package which aims to provide a collection of ggplot2 themes for RTL languages (mostly Persian).
## Installation
The package is not currently available on CRAN but you can install the package using the following line of code:
```{r eval=FALSE, include=TRUE}
remotes::install_github('mcnakhaee/delgosha')
```
## Usage
The package includes three types of functions:
- functions that start with `theme_` change the theme of the ggplot2 visualization. At the moment the following themes are included in the package:
- functions that start with `import_` import necessary fonts for each theme included in the package.
- functions for palettes like many ggplot2 existing palettes start with `scale_`.
### Themes
The current list of themes include:
`theme_farsh_fa`
`theme_hamshahri`
`theme_hamshahri_modern`
`theme_digikala`
`theme_minimal_fa`
`theme_fa`
#### Examples
##### An example of farsh theme:
```{r fig.height=5, fig.width=7, message=FALSE, warning=FALSE,dpi=1000}
library(delgosha)
library(tidyverse)
spotify <- dadegan::spotify
spotify %>%
filter(artist_name %in% c('Alireza Eftekhari','Mohammadreza Shajarian','Alireza Ghorbani')) %>%
ggplot((aes(valence,popularity,color = artist_name_farsi))) +
geom_point(alpha = 0.6,size = 3) +
labs(x = 'شادی',
y = 'محبوبیت',
title = 'مقایسه ای بین محبوبیت و شادی آهنگ های سه خواننده محبوب سنتی',
subtitle = '',
caption = 'مصورسازی: محمد چناریان نخعی',
color = '') +
facet_wrap(~artist_name_farsi) +
scale_color_farsh() +
theme_farsh_fa()
```
##### Hamshahri theme
Based on the main colors of Hamshahri news logo, I designed a theme for ggplot2. Note that this theme does not necessarily represent plots shown in Hamshahri (if such plots even exist!).
```{r fig.height=5, fig.width=7, message=FALSE, warning=FALSE, dpi=1000 }
factnameh <- dadegan::factnameh
tags_count <- factnameh %>%
count(tags, sort = TRUE) %>%
filter(!is.na(tags)) %>%
slice(1:10)
tags_count %>%
ggplot(aes(fct_reorder(tags, n), n)) +
geom_col() +
coord_flip() +
labs(
x = '',
y = '',
title = 'موضوعات با بیشترین تعداد درستی سنجی',
subtitle = 'بیشترین برچسب هایی که در مقالات درستی سنجی وبسایت فکت نامه مورد استفاده قرار گرفته اند.'
) +
theme_hamshahri()
```
There is also modern version of Hamshari's theme which can be used by `theme_hamshahri_modern` function.
```{r fig.height=5, fig.width=7, message=FALSE, warning=FALSE, dpi=1000 }
tags_count %>%
ggplot(aes(fct_reorder(tags, n), n)) +
geom_col() +
coord_flip() +
labs(
x = '',
y = '',
title = 'موضوعات با بیشترین تعداد مقالات درستی سنجی شده',
subtitle = 'بیشترین برچسب هایی که در مقالات درستی سنجی وبسایت فکت نامه مورد استفاده قرار گرفته اند.',
caption = 'منبع: وبسایت فکت نامه'
) +
theme_hamshahri_modern()
```
#### Digikala theme
Based on the characteristics of plots used in their annual report I designed the following theme. Note that probably in the original Digikala's plots, the IranSans font is used which requires a proprietary license. So, I used the Yekan font in this theme.
```{r echo=TRUE, fig.height=5, fig.width=7, message=FALSE, warning=FALSE, dpi=1000}
tags_count %>%
ggplot(aes(fct_reorder(tags, n), n)) +
geom_col() +
coord_flip() +
labs(
x = '',
y = '',
title = 'موضوعات با بیشترین تعداد مقالات درستی سنجی شده',
subtitle = 'بیشترین برچسب هایی که در مقالات درستی سنجی وبسایت فکت نامه مورد استفاده قرار گرفته اند.',
caption = 'منبع: وبسایت فکت نامه'
) +
theme_digikala()
```
```{r echo=TRUE, dpi=1000}
library(Shafaf)
library(ggthemes)
research_studies %>%
count(`نام سازمان`, sort = TRUE) %>%
slice(1:10) %>%
ggplot(aes(x = `نام سازمان`, y = n ,fill = `نام سازمان` )) +
geom_col(alpha = 0.5,show.legend = FALSE) +
labs(title = 'سازمان های شهرداری با بیشترین تعداد پروژه تحقیقاتی',
y = 'تعداد',
caption = 'منبع: سایت شفاف شهرداری تهران') +
scale_fill_tableau() +
coord_flip()+
theme_minimal_fa()
```
#### `theme_fa`
This theme can transform existing ggplot2 themes to a Persian theme.
```{r, fig.height=25,fig.width=25}
library(waffle)
colors <- c(
'ahmadinejad' = '#F94144',
'karrubi' = '#9c89b8',
'mousavi' = '#43AA8B',
'rezai' = '#577590',
'voided_votes' = '#F3722C'
)
iran_election_2009 %>%
ggplot(aes(fill = candidate, values = share_votes)) +
geom_waffle(
n_rows = 10,
size = 2,
make_proportional = TRUE,
color = 'white',
flip = TRUE
) +
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
scale_fill_manual(
values = colors,
labels = c('احمدی نژاد',
'کروبی',
'موسوی',
'رضائی',
'آرای باطله')
) +
labs(title = 'سهم رای کاندیدهای ریاست جمهوری در انتخابات سال 88',
fill = '') +
facet_wrap(~ name_farsi) +
theme_void() +
theme_fa(
strip_text_size = 25,
plot_title_size = 35,
plot_title_margin = 20
) +
theme(
plot.margin = margin(30, 30, 30, 30),
legend.position = 'top',
legend.text = element_text(size = 25, margin = margin(b = 10)),
strip.text = element_text(margin = margin(t = 10, b = 10)),
panel.spacing.x = unit(2, "lines"),
panel.spacing.y = unit(2, "lines")
)
```
#### Aljazeera theme
Based on Aljazeera's font.
```{r, message=FALSE, warning=TRUE, dpi=1000}
library(quRan)
library(ggwordcloud)
library(tidytext)
quran_ar %>%
unnest_tokens(word,text) %>%
count(word,revelation_type,sort = TRUE) %>%
slice(1:200) %>%
mutate(revelation_type = plyr::mapvalues(revelation_type,c('Medinan','Meccan'),c('مدني',
'مكي'))) %>%
ggplot(aes(label = word,size = n,color = revelation_type)) +
geom_text_wordcloud(family = 'Aljazeera') +
scale_size_area(max_size = 15) +
facet_wrap(~revelation_type) +
labs(title = 'سحابة كلمات في القرآن') +
theme_aljazeera()
```
### Fonts
Each theme uses a font which you might not have on your computer. If you don't have these fonts installed on your machine or loaded in your R session the plots will become ugly. So, first you need to install the fonts on your computer. you can run `import_{font_name}` functions to find where the fonts in the package are stored and install theme. After installing these fonts you can run `import_{font_name}` functions again to load the fonts into your R session.
For instance, you can load the vazir font used in farsh theme using the following function:
```{r eval=FALSE}
import_vazir()
```
Alternatively, you can import all fonts with the `import_all_fonts()` function.
### Issues and improvements
If you have found an issue you can send an email to [email protected] or you can open an issue in the package's github repository.
### License
This package is distributed under MIT License.