R: bar plot with two groups, of which one is stacked

前端 未结 2 576
無奈伤痛
無奈伤痛 2020-12-16 03:17

I\'ve encountered a small problem when creating a bar plot in R. There are 3 variables:

a <- c(3,3,2,1,0)
b <- c(3,2,2,2,2)
c <- 0:4
2条回答
  •  执笔经年
    2020-12-16 03:45

    Try the lattice lib:

    library("lattice")
    MyData <- as.data.frame(Titanic)
    
    barchart(Freq ~ Survived | Age * Sex, groups = Class, data = MyData,
             auto.key = list(points = FALSE, rectangles = TRUE, space
             = "right", title = "Class", border = TRUE), xlab = "Survived",
             ylim = c(0, 800))
    

    As you can see the grouping and ploting is done at once.

    Please also see: https://stat.ethz.ch/pipermail/r-help/2004-June/053216.html

提交回复
热议问题