简体   繁体   English

按组添加颜色

[英]Added color by group

Hi everyone!大家好! I try combined boxplot and stripchart to represent some data, and trying to color by group:我尝试结合箱线图和条形图来表示一些数据,并尝试按组着色:

xfact yvar Non-response 0.0012 Non-response 0.0002 Non-response 0.0018 Non-response 0.0004 Non-response 0.0013 Non-response 0.0004 Non-response 0.0029 Non-response 0.0016 Response 0.0177 Response 0.0335 Response 0.0118 Response 0.0309 Response 0.0314 Response 0.0135 XFACT YVAR无反应0.0012无反应0.0002无反应0.0018无反应0.0004无反应0.0013无反应0.0004无反应0.0029非反应0.0029非反应0.0016响应0.0177响应0.0177响应0.035响应0.0335响应0.0335响应0.01118响应0.0118响应0.0314 0.0314

That my code:我的代码:

boxplot(yvar~xfact, data = my.data, ylab= "CD8/GAPDH relative expression", 
names = c("Non-response n=14", "Response n=6"), outpch =NA)  
stripchart(yvar~xfact, data = my.data, vertical = TRUE, method = 
"overplot", pch = 21, col = "black", bg = c("green", "red"), add= TRUE) 

So I expect colored green for non-response and red for response, instead I have some weird output: my output所以我希望绿色表示无响应,红色表示响应,相反我有一些奇怪的 output:我的 output

So can your help me to color by group(non-response and response) not randomly?那么你能帮我按组(不响应和响应)而不是随机着色吗?

This is not really a solution, only a work-around.这不是真正的解决方案,只是一种解决方法。

Assigning a color ( col ) by group works, so you could use按组分配颜色( col ),以便您可以使用

boxplot(yvar~xfact, data = my.data, ylab= "CD8/GAPDH relative expression", 
    names = c("Non-response n=14", "Response n=6"), outpch =NA)  
stripchart(yvar~xfact, data = my.data, vertical = TRUE, 
    method = "overplot", pch = 16, col = c("green", "red"), add = T) 

If you really want to get the appearance of a circle with a border, you can add the border separately.如果你真的想得到一个带边框的圆形的外观,你可以单独添加边框。

boxplot(yvar~xfact, data = my.data, ylab= "CD8/GAPDH relative expression", 
    names = c("Non-response n=14", "Response n=6"), outpch =NA)  
stripchart(yvar~xfact, data = my.data, vertical = TRUE, 
    method = "overplot", pch = 16, col = c("green", "red"), add = T) 
stripchart(yvar~xfact, data = my.data, vertical = TRUE, 
    method = "overplot", pch = 21, col="black", add = T) 

带有添加条形图的箱线图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM