计算框前如何获取geom_boxplot以应用y限制? [英] How to get geom_boxplot to apply y-limits before calculating boxes?

查看:24
本文介绍了计算框前如何获取geom_boxplot以应用y限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是箱线图:

qplot(cyl, mpg, data=mtcars) +
  geom_boxplot() +
  scale_y_continuous()

看起来像这样:

现在我将限制添加到y轴:

Now I add limits to the y axis:

qplot(cyl, mpg, data=mtcars) +
  geom_boxplot() +
  scale_y_continuous(limits=c(0,20))

整个图片都会改变:

我如何获得与第一张相同的图片,只是其中的视口"显示y = 0到20?

How do I get the same picture as the first, just with a 'viewport' showing y=0 to 20?

然后..第二张图片是什么?看来确实有数据丢失(例如:cyl = 4 3-4点).

And .. what is the second picture? It looks like there is actually data missing (example: 3-4 points for cyl=4).

推荐答案

从joran的评论来看,这可行:

From joran's comment, this works:

qplot(cyl, mpg, data=mtcars) +
  geom_boxplot() +
  coord_cartesian(ylim=c(0,20))

来自文档:

缩放绘图显示有两种方法:使用比例或使用坐标系.它们以两种截然不同的方式工作.

There are two ways of zooming the plot display: with scales or with coordinate systems. They work in two rather different ways.

在比例尺上设置限制将丢弃所有不符合条件的数据在这些限制之内.这等效于绘制原始数据

Setting the limits on a scale will throw away all data that's not inside these limits. This is equivalent to plotting a subset of the original data

在坐标系上设置极限会进行可视缩放数据没有变化,我们只查看其中的一小部分原始情节.

Setting the limits on the coordinate system performs a visual zoom the data is unchanged, and we just view a small portion of the original plot.

谢谢乔兰!

这篇关于计算框前如何获取geom_boxplot以应用y限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆