2015-11-01 58 views
0

我想要一个带有2个变量(2 y轴)叠加的barplot。带2 y轴的叠加barplot

这是我的阴谋

enter image description here

而这正是即时寻找。

enter image description here

这里是所有的数据。

我曾经做过什么。

ylim3 <- max(mesbar) + 2000 
mesbar <- c(total_septiembre, total_octubre) 
barplot(mesbar, main = "Month income", 
     ylim = c(0,ylim3)) 
grid() 

> mesbar 
[1] 1260 12710 

,我想用这个数据来overlapp它(天的工作)

> dias_trabajados_sep 
[1] 2 
> dias_trabajados_oct 
[1] 22 

回答

1

这是可以做到。但请记住,您正在玩​​轴ylims,观众可能会说这是误导性的。诀窍是添加par(new = TRUE)和新的barplot。我选择添加蓝色槽rgb,因为它允许透明度通过其alpha参数。这在灰色条比蓝色条更短时很有用。

mesbar <-c(1260,12710) 
dias <- c(2,22) 
ylim3 <- max(mesbar) + 2000 
#mesbar <- c(total_septiembre, total_octubre) 
barplot(mesbar, main = "Month income", 
     ylim = c(0,ylim3)) 
grid() 
par(new = TRUE) 
barplot(dias, main = "Month income", col=rgb(0,0,1, alpha=.5),xaxt = "n",yaxt="n",xlab="",ylab="", ylim=c(0,30)) 
axis(side=4) 

enter image description here

+0

这是完美的!非常感谢 –

+0

非常感谢您的帮助和时间 –