Retrieving it from the ggplot grob is much more complicated now, because of the lack of easy accessor functions in the new gtable structure used by ggplot. It's possible, but ugly. The hard thing about getting the scale breaks is that they're not computed until the ggplot object is rendered, which probably why you had to extract it from the grob in the past.
You can get similar information is to create a scale and train it on your data. For example, this will create a continuous x scale object, train it on the values 1:10, and then retrieve information about the breaks, labels, and range.
sc <- scale_x_continuous()
scale_train_df(sc, data.frame(x = 1:10))
ggplot2:::scale_break_info(sc)
This can be done without even creating a ggplot object. The drawback is that if your plot has stats that modify the data, then the breaks won't match what you get here.
If you must get the labels from the grob, here's some code that does that. Like I said before, it's ugly:
# Create a grob from ggplot
p <- qplot(1:3, 1:3, colour=1:3)
g <- ggplotGrob(p)
g$layout
# t l b r z clip name
# 9 1 1 6 6 0 on background
# 1 3 3 3 3 3 off axis-l
# 2 4 3 4 3 1 off spacer
# 3 3 4 3 4 2 on panel
# 4 4 4 4 4 4 off axis-b
# 5 5 4 5 4 5 off xlab
# 6 3 2 3 2 6 off ylab
# 7 3 5 3 5 7 off guide-box
# 8 2 4 2 4 8 off title
# Here's a simple accessor functions for the grobs:
gt_getgrob <- function(gt, pattern) {
idx <- grep(pattern, gt$layout$name)
if (length(idx) > 1)
stop("More than one match for pattern '", pattern, "'")
gt$grobs[[idx]]
}
# Get each of the axes
axis_l <- gt_getgrob(g, "axis-l")
axis_b <- gt_getgrob(g, "axis-b")
# Draw them
grid.newpage()
grid.draw(axis_l)
grid.draw(axis_b)
# Extract the labels
axis_l$children[[2]]$grobs[[1]]$label
axis_r$children[[2]]$grobs[[2]]$label
-Winston