简体   繁体   English

在R中为箱形图着色

[英]Colouring a boxplot in R

I would like to color a barplot as follows: 我想按如下所示绘制小样图: 在此处输入图片说明

And I tried the following: 我尝试了以下方法:

 boxplot(a,col=rep(c("blue","orange","green","pink","grey"),each=5))

Here "a" represents an affybatch object. 此处的“ a”代表一个affybatch对象。

Of course the above code colors every five bars, and what I really need is color the first six in blue and the next five in orange and so on. 当然,上面的代码每五个小节上色一次,而我真正需要的是将前六个颜色设为蓝色,接下来的五个颜色设为橙色,依此类推。

Or even coloring the first ten in blue and the next three in orange and the remaining again in blue would also help.I did not use ggplot because this is an affybatch object. 甚至将前十个颜色涂成蓝色,然后将后三个颜色涂成橙色,其余的再涂成蓝色也可以。我没有使用ggplot,因为这是一个affybatch对象。

I have no idea what affybatch is, but if what you're trying to do is get a character vector with the first set repeated 6 times, the next 3 5 times, and the last 6 times (as per your graph), try: 我不知道什么是affybatch ,但是如果您要执行的操作是获取一个字符向量,并将第一个集合重复6次,然后将其重复3次5次,最后6次(根据您的图表),请尝试:

rep(c("blue","orange","green","pink","grey"), c(6, 5, 5, 5, 6))
#  [1] "blue"   "blue"   "blue"   "blue"   "blue"   "blue"   "orange" "orange" "orange"
# [10] "orange" "orange" "green"  "green"  "green"  "green"  "green"  "pink"   "pink"  
# [19] "pink"   "pink"   "pink"   "grey"   "grey"   "grey"   "grey"   "grey"   "grey"  

Notice the second argument to rep . 注意rep的第二个参数。

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

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