I think you found Hadley's response which was to use the subset
command and not to think about picking a facet:
http://stackoverflow.com/questions/1570379/adding-stat-smooth-in-to-only-1-facet-in-ggplot2
That leaves you more flexible if you later adjust the layout of your
grid. I don't know of a way to target specific locations in the grid
apart from using the faceting variables.
# reproducible example
library(ggplot2)
data(mpg)
p <- ggplot(mpg, aes(hwy, cty)) + geom_point()
p + geom_abline(intercept = 20, slope = 0, subset = .(cyl == 4)) +
facet_wrap(~cyl)
# I don't quite entirely understand the following behavior
# if you try using subset with geom_hline instead of geom_abline you
need to map the yintercept in an aes call
# doesn't work
p + geom_hline(yintercept = 20, subset = .(cyl == 4)) +
facet_wrap(~cyl)
## Error in eval(expr, envir, enclos) : object 'cyl' not found
# alternative subset syntax just gets ignored
p + geom_hline(yintercept = 20, data = subset(mpg, cyl == 4)) +
facet_wrap(~cyl)
# both work after you map
p + geom_hline(aes(yintercept = 20), subset = .(cyl == 4)) +
facet_wrap(~cyl)
p + geom_hline(aes(yintercept = 20), data = subset(mpg, cyl == 4)) +
facet_wrap(~cyl)
Thanks,
Allan
(R 2.11.1; x86_64-pc-linux-gnu; ggplot2_0.8.8 proto_0.3-8
reshape_0.8.3 plyr_1.1)