ggplot2 bar plot with two categorical variables

前端 未结 2 1950
时光说笑
时光说笑 2020-12-29 14:16

Suppose I have the following data:

Fruit <- c(rep(\"Apple\",3),rep(\"Orange\",5))
Bug <- c(\"worm\",\"spider\",\"spider\",\"worm\",\"worm\",\"worm\",\"         


        
2条回答
  •  感情败类
    2020-12-29 14:44

    Fruit <- c(rep("Apple",3),rep("Orange",5))
    Bug <- c("worm","spider","spider","worm","worm","worm","worm","spider")
    
    df <- data.frame(Fruit,Bug)
    
    ggplot(df, aes(Fruit, ..count..)) + geom_bar(aes(fill = Bug), position = "dodge")
    

    enter image description here

提交回复
热议问题