shadow text grob: shadowtextGrob()
and grid.shadowtext()
library(shadowtext)
grid.shadowtext("grid is awesome", gp=gpar(cex=3, col="white"), rot=45)
grid.shadowtext("hello world", y=0.85, gp=gpar(cex=5, col="steelblue"), bg.colour="firebrick")
grid.shadowtext("R you ready!!!", y=.1, gp=gpar(cex=4, col="firebrick"))
ggplot2 layer: geom_shadowtext()
library(ggplot2)
<- function(n=1, length=10) {
random_text <- data.frame(n=1:n, length=length)
d sapply(1:nrow(d), function(i) {
paste(sample(c(0:9, letters, LETTERS),
$length[i], replace=TRUE),
dcollapse="")
})
}
<- 10
n set.seed(2017-10-27)
<- data.frame(x = rnorm(n), y=rnorm(n),
d label = random_text(n),
angle = sample(0:360, 10))
<- ggplot(d, aes(x, y)) + xlim(-2, 2.2) + ylim(-2, 2.4)
p
+ geom_shadowtext(aes(label=label, angle=angle), size=5) p
+ geom_shadowtext(aes(label=label, angle=angle, color=label),
p bg.colour='firebrick', size=5) +
theme(legend.position="none")
axis text is also supported:
<- c("a","b","c","d","e","f")
x <- c("10", "9","-10","11","-3","-15")
y <- data.frame(x, y)
data $y <- as.numeric(as.character(data$y))
data
$category <- ifelse(as.numeric(data$y)<0, 0, 1)
data$category <- as.factor(data$category)
data
<- ggplot(data, aes(x = x, y = y)) +
g geom_bar(stat = "identity", aes(fill = category))
+ theme(axis.text.x = element_shadowtext(
g colour = "white",
size = 12,face = "bold"))