Hello Folks,
Last week I asked a question to Hadley and he suggested I asked it here.
Since then, I’ve solved the problem, but he solution is quite fiddly.
Any suggestion is appreciated.
Here is the problem:
Looking at facet_grid:
p <- ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2)
p + facet_grid(clarity ~ cut)
If I want to put a title on “clarity”, I can do:
p + facet_grid(clarity ~ cut) +opts(title="Clarity")
But is there a simpler way of Putting a Title on the Facets?
I’d like to put “Cut” as the title of the cut facet…
So what I thought was:
# Setting the Theme
theme_set(theme_bw())
# Creating Viewports
VP<- viewport(width=1,height=1, x=0.5,y=0.5)
VP2<- viewport(width=.8,height=.8, x=0.5,y=0.5)
# Creating a Blank plot, witht he title and Facet Y label
OutPlot<- ggplot(diamonds, aes(carat, price))+geom_blank()+opts(title="Plot title",
panel.grid.major=theme_blank(), panel.grid.minor=theme_blank(), panel.border =theme_blank(),
axis.text.x=theme_text(colour= "white"),axis.text.y=theme_text(colour= "white"),
axis.title.x=theme_text(colour= "white"), axis.title.y=theme_text(colour= "white"),
axis.line=theme_segment(colour= "white"),axis.ticks=theme_segment(colour= "white"))+geom_text(aes(x=5, y=10000),angle=90,label="Facet Y label")
# Defining the inner plot as in The help example
p <- ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(binwidth = 0.2)
# Defining the Ineer plot
InPlot <- p + facet_grid(clarity ~ cut)+opts(title="Facet X label", strip.background = theme_blank())
windows()
print(OutPlot, vp=VP)
print(InPlot, vp=VP2)
I just want to make this simpler….
Thanks
Marcelo