I am plotting a dataset using the following:
plot = ggplot(transData, aes(x=Time, y=Value)) +
scale_fill_brewer(palette="Set1") +
facet_grid(Category ~ .) +
geom_line(aes(group=Type,colour=Type, linetype=Type), size=1.5) +
geom_vline(...) +
geom_text(...)
which draws a grid plot between Category and Type in my dataset. However, the geom_vline
and geom_text
make the vertical line and text label appear on every sub plot. Is there a way to to get a single vline and text element on the entire plot? Any suggestions?
Dataset
Class$Time$Type$Total
Class1$283$Category1$1
Class1$276$Category1$1
Class1$260$Category1$1
Class1$450$Category1$1
Class1$572$Category1$9
Class1$667$Category1$9
Class1$535$Category1$10
Class1$579$Category1$10
Class1$522$Category1$12
Class1$231$Category1$12
Class1$774$Category1$13
Class1$7240$Category1$14
Class1$510$Category1$14
Class1$3863$Category1$14
Class1$954$Category1$15
Class1$455$Category1$15
Class1$644$Category1$15
Class1$1859$Category1$15
Class1$413$Category1$16
Class1$13$Category1$19
Class1$22$Category1$19
Class1$13$Category1$19
Class1$14$Category1$19
Class1$523$Category1$19
Class1$123$Category1$19
Class1$684$Category1$19
Class1$350$Category1$19
Class1$581$Category1$19
Class1$28$Category2$18
Class1$18$Category2$18
Class1$17$Category2$18
Class1$73$Category2$18
Class1$17$Category2$18
Class1$18$Category2$18
Class1$17$Category2$18
Class1$73$Category2$18
Class1$25$Category2$18
Class1$74$Category2$18
Class1$18$Category2$18
Class1$78$Category2$18
Class1$19$Category2$18
Class1$75$Category2$18
Class1$51$Category2$18
Class1$24$Category2$18
Class1$32$Category2$18
Class1$94$Category2$18
Class1$80$Category2$18
Class1$19$Category2$18
Class1$34$Category2$18
Class1$73$Category2$18
Class1$28$Category2$18
Class1$78$Category2$18
Class1$84$Category2$18
Class1$77$Category2$18
Class1$85$Category2$18
Class1$80$Category2$18
Class1$82$Category2$18
Class1$72$Category2$18
Class1$17$Category2$18
Class1$87$Category2$18
Class1$78$Category2$18
Class1$74$Category2$18
Class1$74$Category2$18
Script
library(ggplot2)
options(stringsAsFactors = FALSE)
rootdir = "./"
input = paste(rootdir, "Test.txt", sep="")
data = data.frame(Class=data$Class, Type=data$Type, Time=as.numeric(data$Time), Total=as.numeric(data$Total))
plot = ggplot(data, aes(x=Time, y=Total)) +
scale_fill_brewer(palette="Set1") +
facet_grid(Type ~ Class) +
scale_x_log10() +
geom_line(aes(group=Type,colour=Type, linetype=Type), size=1.5) +
geom_vline(aes(xintercept=1), linetype=2) +
geom_vline(aes(xintercept=4), linetype=2) +
geom_vline(aes(xintercept=8), linetype=2) +
geom_vline(aes(xintercept=16), linetype=2) +
geom_text(aes(1, 4, label="Label1")) +
geom_text(aes(4, 3, label="Label2")) +
geom_text(aes(8, 25, label="Label3")) +
geom_text(aes(16, 2, label="Label4")) +
print(plot)
options(stringsAsFactors = TRUE)
Plot
What I want
What is want is that the labels appear only once across the entire plot.