将关键图例添加到R中的多直方图 [英] Adding key legend to multi-histogram plot in R

查看:100
本文介绍了将关键图例添加到R中的多直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在下面的图中添加关键图例

How do I add a key legend to the below plot

我希望在右上角的某个地方有一个关键的图例,上面有两个短的水平彩条,其中红色的应该说整容手术出了问题",蓝色的应该说德国".

I whish to have a key legend somewhere in the upper right corner with two short horizontal color bars, where the red one should say "Plastic surgery gone wrong" and the blue one should say "Germany".

我使用以下代码生成了情节:

I used the following code to produce the plot:

bar2 <- read.table("div/ana-mut[...]/barriers-set-2.dat", sep=" ")
bar2val <- c(bar2$V1, bar2$V2)
bar3 <- read.table("div/ana-mut[...]/barriers-set-3.dat", sep=" ")
bar3val <- c(bar3$V1, bar3$V2)
p1 <- hist(subset(bar2val, bar2val < 30), breaks=30)
p2 <- hist(subset(bar3val, bar3val < 30), breaks=30)
plot(p1, col=rgb(1,0,0,8/9), main="Barrier distribution", xlab="Barrier [kcal/mol]", ylab="Mutant count")
plot(p2, col=rgb(0,0,1,8/9), add=T)

任何提示将不胜感激.

推荐答案

legend命令可以解决问题:

The legend command will do the trick:

legend("topright", c("Germany", "Plastic"), col=c("blue", "red"), lwd=10)

要获得两个短的水平彩色条,只需使用标准线,但增加线的粗细即可.正如Roland所指出的,您还可以使用fill参数:

To get the two short horizontal colour bars just use the a standard line, but increase the line thickness. As Roland pointed out, you can also use the fill argument:

legend("topright", c("Germany", "Plastic"), fill=c("blue", "red"))

有关更多详细信息,请参见?legend.

See ?legend for more details.

这篇关于将关键图例添加到R中的多直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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