我必须在同一个条形图中绘制两个条形图。我可以做到这一点,我只需要帮助命名这两件事。
在Linux终端中使用R环境,我编写以下命令:
data = rbind(c(94,97,100,100,100,100),c(61,80,88,88,92,100))
barplot(data,names.arg=c(10,20,50,100,200,1000),main="Impact of N on trigger/Trojan coverage",xlab="N",ylab="Coverage(%)",beside=TRUE,col=c("darkblue","red"))
我的问题是如何指定蓝色的含义和红色的含义shown here(蓝色 - 0和红色 - 1)。
答案 0 :(得分:2)
看看这个出色的post on Stackoverflow which demonstrates creating a legend in R with identical RGB color values as the plot。这是@Spacedman在其解决方案中提供的代码:
plot(1:3,
col=c("black",rgb(96,123,139, 50, maxColorValue=255),
rgb(225,64,5, 50,maxColorValue=255)),pch=19)
legend("topright", c("Shuffled", "Riffled", "Somosome"), cex=1.0, bty="n",
col=c("black",rgb(96,123,139, 50, maxColorValue=255),
rgb(225,64,5, 50, maxColorValue=255)),pch=19)
答案 1 :(得分:2)
使用功能'图例'
data = rbind(c(94,97,100,100,100,100),c(61,80,88,88,92,100))
barplot(data,names.arg=c(10,20,50,100,200,1000),main="Impact of N on trigger/Trojan coverage",xlab="N",ylab="Coverage(%)",beside=TRUE,col=c("darkblue","red"))
legend(x="topright",legend=c(0,1),fill=c("darkblue","red"))