Texture in barplot for 7 bars in R?

后端 未结 1 459
死守一世寂寞
死守一世寂寞 2020-12-13 15:51

I have 7 different categories per each value in X. I am using barplot to plot these categories. Such graph looks fine in colors printer, but what if I want it to be fine in

相关标签:
1条回答
  • 2020-12-13 16:33

    Along the lines of my comment, you might find the following helpful:

    # data generation ---------------------------------------------------------
    set.seed(1)
    mat <- matrix(runif(4*7, min=0, max=10), 7, 4)
    rownames(mat) <- 1:7
    colnames(mat) <- LETTERS[1:4]
    
    
    # plotting settings -------------------------------------------------------
    ylim <- range(mat)*c(1,1.5)
    angle1 <- rep(c(45,45,135), length.out=7)
    angle2 <- rep(c(45,135,135), length.out=7)
    density1 <- seq(5,35,length.out=7)
    density2 <- seq(5,35,length.out=7)
    col <- 1 # rainbow(7)
    
    
    # plot --------------------------------------------------------------------
    op <- par(mar=c(3,3,1,1))
    barplot(mat, beside=TRUE, ylim=ylim, col=col, angle=angle1, density=density1)
    barplot(mat, add=TRUE, beside=TRUE, ylim=ylim, col=col, angle=angle2, density=density2)
    legend("top", legend=1:7, ncol=7, fill=TRUE, col=col, angle=angle1, density=density1)
    par(bg="transparent")
    legend("top", legend=1:7, ncol=7, fill=TRUE, col=col, angle=angle2, density=density2)
    par(op)
    

    0 讨论(0)
提交回复
热议问题