library("grid")
library("ggplot2")
library("ggfun")
element_roundrect
The element_roundrect
works like element_rect
to draw round rectangle background. We can use it to adjust theme elements, including legend, strip, panel and plot background.
<- ggplot(mpg, aes(displ, cty)) + geom_point()
p <- p + facet_grid(cols = vars(cyl))
p <- p + theme(strip.background=element_roundrect(fill="grey40", color=NA, r=0.15))
p p
<- ggplot(mtcars, aes(mpg, disp, color=factor(cyl), size=cyl)) +
p2 geom_point()
+ theme(legend.background=element_roundrect(color="#808080", linetype=2)) p2
gglegend
<- ggplot(mtcars, aes(mpg, disp)) + geom_point()
p <- data.frame(colour = c("red", "blue"), VALUE = c("A", "B"))
data gglegend(aes(colour = VALUE, label=VALUE), data, geom_text, p)
set_font
<- data.frame(x=rnorm(10), y=rnorm(10), lab=LETTERS[1:10])
d <- ggplot(d, aes(x, y)) + geom_text(aes(label=lab), size=5)
p set_font(p, family="Times", fontface="italic", color='firebrick')
facet_set
Manually specifying facet labels.
library(ggplot2)
library(ggfun)
<- ggplot(mtcars, aes(disp, drat)) +
p geom_point() +
facet_grid(cols=vars(am), rows=vars(cyl))
+ facet_set(label=c(`0`="Zero", `6`="Six")) p
Supports labeller:
+ facet_set(label=label_both) p
Add a facet label to a plot.
+ facet_set(label="TEST") p
With the ggplotify package, we can use facet_set
to add a facet label to almost any plot in R.
## please try:
::as.ggplot(~barplot(1:10, col=rainbow(10))) +
ggplotifyfacet_set('a barplot in base')