# Plot text along an arbitrary path
t <- seq(-1, 5, length.out = 1000) * pi
spiral <- data.frame(
x = rev(sin(t) * 1000:1),
y = rev(cos(t) * 1000:1),
s = seq(1, 10, length.out = 100),
text = paste(
"Like a circle in a spiral, like a wheel within a wheel,",
"never ending or beginning on an ever spinning reel"
)
)
ggplot(spiral, aes(x, y, label = text)) +
geom_textpath(size = 7, vjust = 2, linewidth = 0) +
coord_equal(xlim = c(-1500, 1500), ylim = c(-1500, 1500))
# Use geom_textline as a drop-in for geom_line
df <- data.frame(x = rep(1:100, 3),
y = sin(c(seq(0, pi, len = 100),
seq(pi, 2*pi, len = 100),
rep(0, 100))),
label = rep(c("y is increasing",
"y is falling",
"y is flat"), each = 100))
ggplot(df, aes(x, y, label = label, color = label)) +
geom_textline(size = 6) + theme(legend.position = "none")
# Rich text labels can contain a subset of HTML tags
label <- paste0(
"Indometacin (",
"C19H16",
"Cl",
"N",
"O4",
") concentration"
)
# These are interpreted when `rich = TRUE`
ggplot(Indometh, aes(time, conc)) +
geom_point() +
geom_labelpath(
label = label,
stat = "smooth", formula = y ~ x, method = "loess",
vjust = -3, size = 8, rich = TRUE
) +
scale_x_log10()
Run the code above in your browser using DataLab