R boxplot: How to customize the appearance of the box-and-whisker plots (e.g., remove lines or borders, change symbol of outliers)

戏子无情 提交于 2019-12-18 10:19:42

问题


Today, I was wondering how to customize the appearance of the box-and-whisker plots. E.g., I wanted to remove the line around the box. However, the problem is, that the border argument changes the color of all lines of the box-and-whisker plots simultaneously. So, if one has the great idea to set border = "white" then the whiskers are also going to “disappear” and you have a white line representing your median.

As I could not find a solution on the internet dealing with exactly my problem, I fiddled around a little and figured some mighty settings which seem to be nearly undocumented as a whole. These settings allow you to customize the appearance of your box-and-whisker plots to a large extend. I know, some of the features have already been unveiled on stackoverflow (e.g. here). However, I could not find a complete documentation. Thus, this post.


回答1:


For complete documentation you should look at ?bxp (linked from the ... description in ?boxplot, and in the "See Also" in ?boxplot, and in the pars description in ?boxplot.). It documents that outpch can change the shape of the outliers (though pch works fine too). It also has boxlty, boxlwd, boxcol and boxfill for the box, and many others for the whiskers, the staples, median line...




回答2:


In order to customize the appearance of the box-and-whisker plots, you have to change the med[…], box[…], whisk[…], or staple[…] argument for adjusting the line settings, or the out[…] argument for outliers.

[…] needs to be replaced by one of the following line or point arguments:

Arguments for the appearance of line elements (for more information see ?par in R):

  • lty: line style (e.g.,= 0 to remove the line,= 1 for solid line)
  • lwd: line width
  • col: line color

Arguments for the appearance of outliers (for more information see ?points in R):

  • pch: symbol style
  • lwd: line width
  • cex: size of symbol
  • col: color
  • bg: background color

So, here is an example of how the above boxplot might be "customized":

boxplot( … , medcol = "red", boxlty = 0, whisklty = 1, staplelwd = 4, outpch = 8, outcex = 3)

This leads to the following boxplot:



来源:https://stackoverflow.com/questions/28889977/r-boxplot-how-to-customize-the-appearance-of-the-box-and-whisker-plots-e-g-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!