bwplot中线代替点

时间:2018-07-05 23:16:22

标签: r

我被指示仅将bwplot用于以下用途。我被指示对美学进行一些调整,以使箱形图更易于阅读。使用HH软件包bwplot,默认情况是在箱形图的中间有一个点。我想做的是将此点更改为一行以显示中位数。下面是到目前为止的代码,但是我无法找到如何将点更改为一行。请注意,如果您安装了HH软件包,那么我将在该软件包中使用数据集'draft70mn'。

我确实知道,对于所使用的软件包,这实际上是不可能的。但是,如果是这样,我想学习如何使用此软件包。

data(draft70mn) # calls the dataset - the dataset is named draft70mn
head(draft70mn) # displays the first 6 lines of the dataset

draft70 <- stack(draft70mn) 
# reformats the dataset and renames it draft70

draft70$quarter <- factor(c(rep(1, 93), rep(2, 93),
                            rep(3, 93), rep(4, 93)))
# adds a new variable to the dataset draft70, this new variable is
# labeled quarter and it identifies the quarter of the year for each 
# date

draft70$ind <- factor(draft70$ind, levels=names(draft70mn))
# makes the variable ind (month) a factor with levels.  This tells R 
#that the names of the month have a meaningful order (Jan, Feb,..) 
#and should not be placed in alphabetical order

draft70 <- draft70[!is.na(draft70$values), ]
#removes missing data, that is, removes day 31 in months with 
#only 30 days or less    

bwplot(values ~ ind, data = draft70, arrange = TRUE,
       panel = panel.bwplot.superpose, groups = ind,
       ylab = 'Draft Number',
       xlab = 'Month')

任何对此的帮助都很棒。

1 个答案:

答案 0 :(得分:0)

我发现添加“ pch ='|'可以解决问题。bwplot的最终代码如下:

bwplot(values ~ ind, data = draft70, arrange = TRUE,
   panel = panel.bwplot.superpose, groups = ind,
   ylab = 'Draft Number',
   xlab = 'Month',
   pch = '|') ##Omitting this will result in the line reverting back to a dot.

下面的输出图片。

enter image description here