用bwplot分组了水平boxplot [英] Grouped horizontal boxplot with bwplot

查看:162
本文介绍了用bwplot分组了水平boxplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,可通过lattice中的bwplot函数对垂直框进行分组.可重现的例子.

I have the following code that allows grouped vertical box-plots via the bwplot function in lattice. Reproducible example..

data(mpg, package = "ggplot2") 

bwplot( hwy~class, data = mpg, groups = year,
    pch = "|", box.width = 1/3,
    auto.key = list(points = FALSE, rectangles = TRUE, space = "right"),
    panel = panel.superpose,
    panel.groups = function(x, y, ..., group.number) {
        panel.bwplot(x + (group.number-1.5)/3, y, ...)
     })

这很好,但是我希望框线图是水平的,所以我更改了第一行,使其他所有内容保持相等:

This works fine, but I would like the boxplots to be horizontal, so I changed the first line, keeping everything else equal:

bwplot( class~hwy, data = mpg, groups = year, ...

但是图形如下所示:.我尝试使用该代码没有成功.我有两个问题:首先,我该如何做,还是有可能不将箱形图叠加在一起?其次,更普遍地说,如何将颜色面板设置为灰度,以使绘图显示为灰色阴影或黑白阴影?

But the graph comes out like this . I have tried playing around with the code without success. I have 2 questions: Firstly, how can I, or is it possible to have the boxplots not superimposed on each other? And secondly and more generally, how can I set the color panel to grayscale, so the plot come out in shades of gray or just black and white?

推荐答案

如果使用bwplot并不重要,则可以尝试ggplot:

If it's not critical that you use bwplot, you may try ggplot:

ggplot(data = mpg, aes(x = class, y = hwy, fill = factor(year))) +
  geom_boxplot() +
  coord_flip() +
  scale_fill_grey(start = 0.5, end = 0.8) +
  theme_classic()

这篇关于用bwplot分组了水平boxplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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