-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunnR.Rmd
147 lines (110 loc) · 3.25 KB
/
funnR.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
---
title: "funnR"
author: "Vanessa Tobias <[email protected]>"
date: "August 7, 2019"
output: html_document
---
This isn't the most complete or exciting R markdown file you've ever found, but hopefully it's one of the funner ones. The purpose of this document is just to explore some fun and silly things that I've found in R.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# #install.packages("devtools") #requires recent version of R
# library(devtools)
# install_github("Gibbsdavidl/CatterPlots")
# devtools::install_github("melissanjohnson/pupR")
# install.packages("cowsay")
library(CatterPlots)
library(pupR)
library(car)
library(cowsay)
library(praise)
library(ggplot2)
data(mtcars)
motors <- mtcars
```
# R for Dog lovers
```{r}
pupR()
#praise()
text(x= 300, y = 50, praise(), col = "yellow", cex = 2)
```
```{r}
e <- simpleError("test error")
tryCatch(stop(e), error = function(e){
pupR()
text(x= 300, y = 50,"Error Therapy pupR", col = "orange", cex = 2)
})
```
## Let's make some CatterPlots!
Source for CatterPlots: https://github.com/Gibbsdavidl/CatterPlots
```{r}
purr <- catplot(xs=motors$disp, ys=motors$wt, cat=5, size = 0.1,
catcolor='#000000FF')
#cats(purr, -x, -y, cat=4, catcolor='#FF0000')
```
```{r}
meow <- multicat(xs=motors$disp, ys=motors$wt,
cat=c(1,2,3,4,5,6,7,8,9,10),
catcolor=list('#000000FF'),
canvas=c(-0.1,1.1, -0.1, 1.1),
xlab="some cats", ylab="other cats", main="Random Cats")
```
# Sound with R
```{r}
library(beepr)
beep(3)
beep(8)
```
Make R play happy birthday: https://correlaid.org/en/blog/music-with-r/
# xkcd plots
```{r}
download.file("http://simonsoftware.se/other/xkcd.ttf", dest="xkcd.ttf", mode="wb")
system("mkdir ~/.fonts")
system("cp xkcd.ttf ~/.fonts")
font_import(paths = ".", pattern = "[X/x]kcd", prompt=FALSE) #change the path to where R saved the font file
fonts()
fonttable()
if(.Platform$OS.type != "unix") {
## Register fonts for Windows bitmap output
loadfonts(device="win")
} else {
loadfonts()
}
windowsFonts(xkcd=windowsFont("TT xkcd"))
library(xkcd)
```
```{r}
xrange <- range(mtcars$mpg)
yrange <- range(mtcars$wt)
set.seed(123) # for reproducibility
p <- ggplot() +
geom_point(aes(mpg, wt), data=mtcars) +
#theme_xkcd() +
theme(text = element_text(size = 16, family = "Comic Sans MS")) +
xkcdaxis(xrange,yrange) +
labs(x = "some text")# +
#annotate("text", 11, 4, label = 'text text', hjust = 0, family = "xkcd", size = 10)
p
```
# with crayola colors
```{r}
library(broman)
plot_crayons()
#brocolors("crayons")["Shamrock"]
```
```{r}
p <- ggplot() +
geom_smooth(aes(mpg, wt), data=mtcars, color = brocolors("crayons")["Shamrock"],
se = FALSE, size = 1) +
#theme_xkcd() +
theme(text = element_text(size = 16, family = "Comic Sans MS")) +
xkcdaxis(xrange,yrange) +
labs(x = "", y = "")
p
```
# rphylopic
Potentially useful for real plots, but also really fun!
```{r}
library(rphylopic)
mouse <- image_data("6b2b98f6-f879-445f-9ac2-2c2563157025", size="512")[[1]]
p + add_phylopic(mouse, x=motors$disp, y=motors$wt)
```