在带状图中按组显示点颜色(col)和填充颜色(bg) [英] Point color (col) and fill color (bg) by group in stripchart

查看:179
本文介绍了在带状图中按组显示点颜色(col)和填充颜色(bg)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制以下图像

I'm trying to reproduce the following image image http://www.davidzeleny.net/wiki/lib/exe/fetch.php/vizualizace:figures:boxplots-jitter-rdbu-colors.png?cache=

我正在使用的代码大致如下:

The code I'm using is roughly this:

library(RColorBrewer) 
library(reshape2)

a=rnorm(100, mean=1)
b=rnorm(100, mean=0, sd=1)
ab=data.frame(a,b)
melt=melt(ab)
bpColor=brewer.pal(4, 'RdBu')

boxplot(melt$value ~ melt$variable, notch=T, col=c(bpColor[1], bpColor[4]), outline=F, varwidth=T)
stripchart(melt$value ~ melt$variable, add=T, vertical=T, pch=21,
         bg=bpColor[2:3][melt$variable], method='jitter', jitter=0.02)

我从中得到的几乎是一样的,除了带状图点的颜色

What I'm getting from this is almost the same except for the color of the stripchart points

my_image http://is.muni.cz/de/256262/Rplot. png

我应该如何编辑代码以重现正确的颜色? 我以为那个

How should I edit my code in order to reproduce the proper coloring? I thought, that

bg=bpColor[2:3][melt$variable]

将完成这项工作,但是,如果删除[]括号,我会得到两种输出,但是我得到了两种颜色,但是混合在组中.谢谢您的帮助.

would do the job, however I'm getting this output, if I would erase the [] brackets I got two colors, but mixed within the groups. Thank you advance for your help.

推荐答案

这不是最优雅的方法,但是,它正在工作

Not the most elegant way, but hey, it's working

boxplot(melt$value ~ melt$variable, notch=T, col=c(bpColor[1], bpColor[4]), outline=F, varwidth=T)
stripchart(melt[melt$variable == "a", "value"] ~ melt[melt$variable == "a", "variable"], add=T, vertical=T, pch=21, bg=c(bpColor[2]), method='jitter', jitter=0.02)
stripchart(melt[melt$variable == "b", "value"] ~ melt[melt$variable == "b", "variable"], add=T, vertical=T, pch=21, bg=c(bpColor[3]), method='jitter', jitter=0.02)

这篇关于在带状图中按组显示点颜色(col)和填充颜色(bg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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