开发者

Automatically zooming to stat_summary data

I would like to zoom in on a part of ggplo开发者_如何学JAVAt's graph to focus on the summary statistics.

Let's say we have some data --

data = data.frame(x = c(1,2), y=c(1, 3, 5, 7, 9, 11))

-- and we want to plot only the means --

qplot(x, y, data=data)
+ stat_summary(fun.y=mean, geom="point",color="red")

Normally, I would use scale_y_continuous(limits=...), but when using stat_summary this drops some of the data (see ?stat_summary).

So, I would want to use coord_cartesian(ylim=...). But, this requires manually specifying y limits, and it seems to zoom in on part of the graph, which can leave less sensible background grid --

+ coord_cartesian(ylim=c(4.5,7.5))

-- in this example, filling in only the 6 as a tick mark.

How can one 'shrink-wrap' to zoom in on only stat_summary's displayed data, without specifying limits manually and changing the background grid?

(I actually want to do this with means and confidence intervals, so I would like to use stat_summary.)


currently it is impossible to automatically zoom after stat_summary. As for the ticks and breaks, you can use wise=TRUE in coord_cartesian in ggplot-0.8.9.

data <- data.frame(x = c(1,2), y=c(1, 3, 5, 7, 9, 11))
ggplot(data, aes(x, y)) +
  stat_summary(fun.y=mean, geom="point",color="red") +
  coord_cartesian(ylim=c(4.5,7.5), wise=TRUE)

also see the recent post of the blog: http://kohske.wordpress.com/2010/12/24/zoom-with-break-adjustment-in-ggplot2/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜