你将如何绘制一个盒子的阴谋和具体点在同一个阴谋? [英] How would you plot a box plot and specific points on the same plot?

查看:158
本文介绍了你将如何绘制一个盒子的阴谋和具体点在同一个阴谋?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  qplot(factor(cyl),mpg,data = mtcars,geom = boxplot)

并指向:

  qplot(factor(cyl),mpg,data = mtcars,geom =point)

您如何将两者结合起来 - 只是在框的顶部显示一些特定的要点(比如 wt 小于2) ?

解决方案

使用 + geom_point(...) c $ c> qplot (只需添加一个 + geom_point()即可得到所有绘制的点)。

要有选择地绘制,只需选择要绘制的点:

  n < -  nrow(mtcars )
#绘制每第二个点
idx < - seq(1,n,by = 2)

qplot(因子(cyl),mpg,data = mtcars,geom =boxplot)+
geom_point(aes(x = factor(cyl)[idx],y = mpg [idx]))#< - 参见[idx]?

如果您事先知道这些要点,可以直接输入它们,例如:



pre $ c $ q $ q $因子(c(4,6,8)),y = c(15,20,25)))#plot(4,15),(6,20),...


We can draw box plot as below:

qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot")

and point as:

qplot(factor(cyl), mpg, data = mtcars, geom = "point") 

How would you combine both - but just to show a few specific points(say when wt is less than 2) on top of the box?

解决方案

Use + geom_point(...) on your qplot (just add a + geom_point() to get all the points plotted).

To plot selectively just select those points that you want to plot:

n <- nrow(mtcars)
# plot every second point
idx <- seq(1,n,by=2)

qplot( factor(cyl), mpg, data=mtcars, geom="boxplot" ) +
     geom_point( aes(x=factor(cyl)[idx],y=mpg[idx]) )    # <-- see [idx] ?

If you know the points before-hand, you can feed them in directly e.g.:

qplot( factor(cyl), mpg, data=mtcars, geom="boxplot" ) +
     geom_point( aes(x=factor(c(4,6,8)),y=c(15,20,25)) ) # plot (4,15),(6,20),...

这篇关于你将如何绘制一个盒子的阴谋和具体点在同一个阴谋?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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