special note for windows users
For windows users, you need to register your font before using it in R graphics (see discussion here).
if (.Platform$OS.type == "windows") {
windowsFonts(
Impact = windowsFont("Impact"),
Courier = windowsFont("Courier")
) }
meme
Call meme
to add meme captions:
library(meme)
<- system.file("angry8.jpg", package="meme")
u meme(u, "code", "all the things!")
The grammar of meme
Not that useful, just to mimic ggplot2
:
mmplot(u) + mm_caption("calm down", "and RTFM",
color="purple")
meme_save
: a meme version of ggsave
The meme
output can be saved as an object, and can be exported to file using meme_save
. meme_save
helps user setting up the output figure aspect ratio and calls ggsave
to export the figure:
<- system.file("success.jpg", package="meme")
u2 <- meme(u2, "please", "tell me more") x
<- tempfile(fileext=".png")
outfile meme_save(x, file=outfile)
plot
method
Users can plot
the meme
output and change the caption or other parameters in real time.
plot(x, size = 2, "happy friday!", "wait, sorry, it's monday", color = "firebrick", font = "Courier")
+
method
Instead of using parameters in plot()
explictely, Users can use + aes()
to set the plot parameters:
+ aes(upper = "#barbarplots",
x lower = "friends don't let friends make bar plots",
color = firebrick, font = Courier, size=1.5)
or using + list()
. The following command will also generate the figure displayed above.
+ list(upper = "#barbarplots",
x lower = "friends don't let friends make bar plots",
color = "firebrick", font = "Courier", size=1.5)
multi-language support
I didn’t do anything about it. Multi-language was supported internally. Just simply select a font for your language.
<- meme(u, "卧槽", "听说你想用中文", font="STHeiti")
y y
grid support
library(grid)
<- meme(u, "code", "all the things!", size=.3, color='firebrick', bgcolor=NULL)
mm
grid.newpage()
pushViewport(viewport(width=.9, height=.9))
grid.rect(gp = gpar(lty="dashed"))
<- seq(0, 2*pi , length.out=10)
xx <- sin(xx)
yy
for (i in seq_along(xx)) {
<- viewport(x = xx[i]/(2*pi), y = (yy[i]-min(yy))/2, width=.05, height=.05)
vp print(mm, vp = vp)
}
ggplot2 support
library(ggplot2)
library(ggimage)
<- data.frame(x = xx, y = yy)
d ggplot(d, aes(x, y)) + geom_line() +
geom_subview(aes(x, y), data=d, subview=mm, width=.3, height=.15)
ggplot(d, aes(x, y)) +
geom_subview(x = 0, y = 0, subview=mm+aes(size=3), width=Inf, height=Inf) +
geom_point() + geom_line()
cowplot support
library(cowplot)
plot_grid(x, y, ncol=1, labels = c("A", "B"))
font support
In addition to the fonts installed on your system, there are many amusing fonts that are funny for meme, e.g. fonts on https://fontmeme.com/fonts/.
## import pokemon fonts
## downloaded from <https://fontmeme.com/fonts/pokmon-font/>
font_pokemon()
## font Pokemon_Hollow, Pokemon_Solid loaded...
<- system.file("ash-pikachu.0.0.jpg", package="meme")
u
meme(u, "Pokemon", "pikachu i choose you!", font='Pokemon_Hollow')
meme(u, "Pokemon", "pikachu i choose you!", font='Pokemon_Solid', color='#FCCF00')
You can download fonts and pass the folder to font_import()
to import the fonts so that they can be used to create meme.
## folder that contains bubble1 font
## downloaded from https://fontmeme.com/fonts/bubble-1-font/
<- system.file('fonts/bubble', package='meme')
dir font_import(dir)
## font bubble1 loaded...
meme(u, "the meme package", "is awesome!", font="bubble1")
Fonts imported by font_import()
are not restricted in creating meme, you can use them in other visualization packages.
qplot(1:10, 1:10) + labs(title="meme is awesome") +
theme(plot.title=element_text(family='bubble1', size=30, color='firebrick'))