library(showtext)
## Loading required package: sysfonts
## Loading required package: showtextdb
showtext.auto()
## 'showtext.auto()' is now renamed to 'showtext_auto()'
## The old version still works, but consider using the new function in future code
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1 ✔ purrr 1.0.0
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(ggplot2)
d <- data_frame(t = seq(-pi, 0, .01),
x1 = 16 * (sin(t)) ^ 2,
x2 = -x1,
y = 13 * cos(t) -
5 * cos(2 * t) -
2 * cos(3 * t) -
cos(4 * t)) %>%
gather(side, x, x1, x2)
a = (d$x - min(d$x))/(max(d$x) - min(d$x))
b = (d$y - min(d$y))/(max(d$y) - min(d$y))
g = ggplot(data=d, aes(x=x, y=y)) +
geom_line(aes(color=I('white'))) +
geom_polygon(aes(fill='red'), show.legend = F) +
scale_x_continuous(labels = NULL) +
scale_y_continuous(labels = NULL) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()) +
annotate('text', x=median(a), y=median(b),
label='For you',size=8,col='gray20') +
annotate('text', x=median(a), y=median(b)-2.5,
label='Into you',size=12,col='white') +
annotate('text', x=median(a), y=median(b)-5,
label="I melt.",size=5,col='#eeb401')+
annotate('text', x=median(a), y=median(b)-6.5,
label='All of me',size=4,col='white')
library(tidyverse)
rose_plot = function(){
f <- function(x) x^2 / 2
f1 <- function(x) x^2/5
geom_leaf <- function(x, xend, f, xoffset = 0, yoffset = 0,
xflip = 1, yflip = 1, ...) {
.x <- seq(x, xend, length.out = 100)
.y <- f(.x)
df <- tibble(x = c(.x, .y), y = c(.y, .x))
df$x <- xflip * df$x + xoffset
df$y <- yflip * df$y + yoffset
geom_polygon(aes(x = x, y = y), data = df, ...)
}
geom_rose <- function(n, mean = c(0, 0), ...) {
.x <- mvtnorm::rmvnorm(n, mean)
df <- tibble(x = .x[, 1], y = .x[, 2])
list(
stat_density_2d(
aes(x = x, y = y, fill = stat(level)), data = df,
geom = "polygon", show.legend = FALSE, color = "grey80"),
scale_fill_gradient2(...)
)
}
p <- ggplot() +
coord_equal(1, c(-4, 2), c(-7, 3)) +
geom_curve(aes(x = -1, y = -7, xend = 0, yend = 0),
ncp = 1000, curvature = -0.3, size = 1,
color = "olivedrab3") +
geom_leaf(0, 2, f, -1.6, -4.5, 1,
fill = "olivedrab3", color = "palegreen") +
geom_leaf(0, 2, f, -1.6, -5, -1,
fill = "olivedrab3", color = "palegreen") +
geom_leaf(0, 2, f1, -1.25, -2.25, -0.5,
fill = "olivedrab3", color = "palegreen")+
geom_leaf(0, 3, f1, -1.25, -2.25, 0.5,
fill = "olivedrab3", color = "palegreen") +
geom_rose(1000, mean = c(0, 0),
low = "red", mid = "purple", high = "pink",
midpoint = 0.075) +
theme_void()
return(p)
}
p = rose_plot()
library(patchwork)
g + inset_element(
p,0, 0.15, 1, 0.35
)
