I want to make the following graph of a folded line with a linear curve.
But why does this following code not work? What is the right way to do this?
x<-c(0,1,2,3,4,5,6,7,8,9,10,11,12); # To plot line emp_dens <- c(0.107,0.184,0.205,0.185,0.138,0.091,0.049,0.023,0.01,0.0028,0.0012,0.00023,0.00013); dat_dens <- as.matrix(cbind(x,emp_dens)); # To plot stack bar dens_all_k <- c(1.15e-01, 1.89e-01, 2.05e-01, 1.82e-01,1.36e-01,8.68e-02,4.71e-02,2.21e-02,9.17e-03,3.37e-03,1.11e-03,3.37e-04,9.31e-05) # Each k0..5 compose the stack # For example # dens_k0[1] + .... dens_k5[1] ~= dens_all_k[1] dens_k0 <-c(2.52e-02,8.38e-02,1.38e-01, 1.53e-01,1.27e-01,8.44e-02, 4.66e-02, 2.21e-02, 9.16e-03, 3.37e-03,1.11e-03, 3.37e-04, 9.31e-05) dens_k1 <- c(6.75e-02, 8.91e-02, 5.86e-02, 2.51e-02, 8.59e-03,2.25e-03, 4.90e-04,9.35e-05, 1.55e-05,2.21e-06,2.99e-07, 3.55e-08,3.92e-09) dens_k2 <- c(1.70e-02,1.64e-02,7.95e-03, 2.56e-03,6.20e-04,1.20e-04, 1.93e-05, 2.67e-06, 3.23e-07,3.47e-08,3.36e-09, 2.95e-10,2.38e-11) dens_k3 <- c(0.005124596,0,0,0,0,0,0, 0, 0, 0, 0,0,0) dens_k4 <- c(0.0004270497, 0, 0,0,0, 0, 0, 0, 0,0,0, 0, 0) dens_k5 <- c(2.760725e-05, 0, 0, 0,0,0, 0, 0, 0, 0,0, 0,0) barplot(cbind(0:max(x),dens_all_k),xlim=c(0,max(x)),ylim=c(0,max(emp_dens)),,space=0.1,lwd=5,xlab="Value of X",ylab="Densities",font.main=1); lines(dat_dens,lty=1,col="red");