R

时间:2016-08-04 16:04:45

标签: r histogram

我正在重叠两个直方图,并且希望保持每个直方图以及公共区域。 (3种颜色)。我有以下代码:

 hotel_auto<-subset(hotel_pr_curr,hotel_pr_curr$BFR_CONDITION_1 =="AUTO_BFR")
 hotel_nonauto<-subset(hotel_pr_curr,hotel_pr_curr$BFR_CONDITION_1 == "NON_AUTO_BFR")

 hist_curr1<- hist(hotel_auto$CURR_DIF_RTO, breaks = 20)
 hist_curr2<- hist(hotel_nonauto$CURR_DIF_RTO, breaks = 20)

 hist_curr1$density<-hist_curr1$counts/sum(hist_curr1$counts)*100
 hist_curr2$density<-hist_curr2$counts/sum(hist_curr2$counts)*100
  plot(hist_curr1,freq=FALSE,xlim=c(0,0.8),ylim=c(0,50),ylab="Percentage",col=rgb(0,0,1,1), main="BFR Current-Historical",xlab="Current Historical Difference")

  plot(hist_curr2,freq=FALSE,xlim=c(0,0.8),ylim=c(0,50),ylab="Percentage",col=rgb(1,0.9,0,1), main="",xlab="", add = TRUE)
  legend("topright", c("AUTO_BFR", "NONAUTO_BFR"), cex=0.75, fill=c("blue", "yellow"))

enter image description here

它只有两种颜色,我刚才提到它可以有三种颜色吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

rgb中的最后一个Alpha值是针对alpha的,因此如果您将颜色更改为col=rgb(0,0,1,0.5)col=rgb(1,0.9,0,0.5),您应该能够看到重叠。