1
1
# miscplot.R
2
2
3
- requireNamespace(" grid" ) # for gpar
3
+ requireNamespace(" grid" ) # for gpar, etc.
4
4
requireNamespace(" ggplot2" )
5
5
6
+ library(gridExtra )
7
+ # library(extrafont) # install with sudo. Then (with sudo R) run font_import() then loadfonts(). Then view with fonts() or fonttable(). See https://github.com/wch/extrafont
8
+ library(Cairo )
9
+ library(ggplot2 )
10
+
6
11
# ==============================================================================
7
12
# Namespace-like method: http://stackoverflow.com/questions/1266279/#1319786
8
13
# ==============================================================================
@@ -105,7 +110,7 @@ element_grob.theme_border <- function(
105
110
element_gp <- grid :: gpar(lwd = len0_null(element $ size * .pt ),
106
111
col = element $ colour ,
107
112
lty = element $ linetype )
108
- polylineGrob(
113
+ grid :: polylineGrob(
109
114
x = xlist , y = ylist , id = idlist , ... , default.units = " npc" ,
110
115
gp = modifyList(element_gp , gp ),
111
116
)
@@ -132,7 +137,7 @@ element_grob.theme_L_border <- function(
132
137
element_gp <- grid :: gpar(lwd = len0_null(element $ size * .pt ),
133
138
col = element $ colour ,
134
139
lty = element $ linetype )
135
- polylineGrob(
140
+ grid :: polylineGrob(
136
141
x = c(x + width , x , x ), y = c(y ,y ,y + height ), ... , default.units = " npc" ,
137
142
gp = modifyList(element_gp , gp ),
138
143
)
@@ -159,7 +164,7 @@ element_grob.theme_bottom_border <- function(
159
164
element_gp <- grid :: gpar(lwd = len0_null(element $ size * .pt ),
160
165
col = element $ colour ,
161
166
lty = element $ linetype )
162
- polylineGrob(
167
+ grid :: polylineGrob(
163
168
x = c(x , x + width ), y = c(y ,y ), ... , default.units = " npc" ,
164
169
gp = modifyList(element_gp , gp ),
165
170
)
@@ -186,7 +191,7 @@ element_grob.theme_left_border <- function(
186
191
element_gp <- grid :: gpar(lwd = len0_null(element $ size * .pt ),
187
192
col = element $ colour ,
188
193
lty = element $ linetype )
189
- polylineGrob(
194
+ grid :: polylineGrob(
190
195
x = c(x , x ), y = c(y , y + height ), ... , default.units = " npc" ,
191
196
gp = modifyList(element_gp , gp ),
192
197
)
@@ -248,7 +253,7 @@ element_grob.theme_border_numerictype <- function(
248
253
element_gp <- grid :: gpar(lwd = len0_null(element $ size * .pt ),
249
254
col = element $ colour ,
250
255
lty = element $ linetype )
251
- polylineGrob(
256
+ grid :: polylineGrob(
252
257
x = xlist , y = ylist , id = idlist , ... , default.units = " npc" ,
253
258
gp = modifyList(element_gp , gp ),
254
259
)
@@ -327,11 +332,6 @@ miscplot$multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
327
332
328
333
# http://cairographics.org/manual/cairo-FreeType-Fonts.html
329
334
330
- library(gridExtra )
331
- # library(extrafont) # install with sudo. Then (with sudo R) run font_import() then loadfonts(). Then view with fonts() or fonttable(). See https://github.com/wch/extrafont
332
- library(Cairo )
333
- library(ggplot2 )
334
-
335
335
miscplot $ which_cairo_fonts_available <- function () {
336
336
CairoFontMatch(" :" , sort = TRUE )
337
337
}
@@ -384,7 +384,7 @@ miscplot$save_grob_to_pdf <- function(g, filename, width_mm, height_mm,
384
384
title = title )
385
385
# Cairo automatically embeds fonts:
386
386
# http://cran.r-project.org/web/packages/Cairo/Cairo.pdf
387
- grid.draw(g ) # not: print(g)
387
+ grid :: grid .draw(g ) # not: print(g)
388
388
dev.off()
389
389
}
390
390
}
@@ -395,7 +395,7 @@ miscplot$A4_LARGE_MM <- 297
395
395
miscplot $ POINTS_PER_INCH <- 72
396
396
miscplot $ POINTS_PER_MM <- miscplot $ POINTS_PER_INCH * miscplot $ INCHES_PER_MM
397
397
398
- miscplot $ BLANK_GROB <- rectGrob(gp = grid :: gpar(fill = " white" , alpha = 0 ))
398
+ miscplot $ BLANK_GROB <- grid :: rectGrob(gp = grid :: gpar(fill = " white" , alpha = 0 ))
399
399
# ... alpha=0 makes it invisible
400
400
miscplot $ NOLEGEND <- theme(legend.position = " none" )
401
401
miscplot $ MOVELEGEND_BOTTOMLEFT <- theme(legend.justification = c(0 ,0 ),
0 commit comments