# NOT RUN {
#alter mtcars to make some variables factors
mtcars2 <- mtcars
mtcars2[, c("cyl", "am", "gear")] <- lapply(mtcars[,
c("cyl", "am", "gear")], as.factor)
p <- ggplot(mtcars2, aes(mpg, wt, group = cyl)) +
geom_line(aes(color=cyl)) +
geom_point(aes(shape=cyl)) +
facet_grid(gear ~ am) +
theme_bw()
z <- ggfaxt(ggplot2.object = p, x.coor = 33, y.coor = 2.2,
labels = 1:6, color="red")
#approach 1 (alter the text data frame and pass the qfacet object)
z$dat[5, 1:2] <- c(15, 5)
ggfaxt(z, color="red")
#approach 2 (alter the original ggplot object)
ggfaxt(p, x = c(33, 33, 33, 33, 15, 33),
y = c(2.2, 2.2, 2.2, 2.2, 5, 2.2), 1:6, color="red")
#use "" to not add a label to a facet
ggfaxt(ggplot2.object = p, x.coor = 33, y.coor = 2.2,
labels = c("", letters[1:4], ""), color="red")
#all the same things you can pass to geom_text qfacet_text takes
ggfaxt(z, labels = paste("beta ==", 1:6),
size = 3, color = "grey50", parse = TRUE)
#two labels: same plot
p <- ggplot(CO2, aes(conc, uptake, group = Plant)) +
geom_line(aes(color=Plant)) +
facet_grid(Type ~ Treatment) +
theme_bw()
#plot first text layer
z <- ggfaxt(ggplot2.object = p, x.coor = 250, y.coor = 10,
labels = 1:4, color="red")
#plot second text layer
ggfaxt(ggplot2.object = z$new, x.coor = 900, y.coor = 10,
labels = paste("beta ==", 11:14), color="blue", parse = TRUE)
# }
Run the code above in your browser using DataLab