简体   繁体   中英

How can I generate a bar chart with 4 groups in R?

May you please help me how to generate a bar chart with 4 groups like the picture? 示例图表

No data was provided, so I created a dummy data. I created a use case below, otherwise there are get solutions on SO, such as Simplest way to do grouped barplot .

library(tidyverse)

# Data
trees <- data.frame(age = sample(c("Old", "Adult", "Young"), 
                                 size = 20, replace = TRUE, prob = c(.5, .25, .25)), 
                    tree = factor(sample(1:5, size = 20, replace = TRUE)), 
                    circumference = rnorm(n = 20, mean = 60, sd = 15))

trees %>% 
  ggplot(aes(x = age, y = circumference, fill = tree)) + 
  geom_col(position = "dodge") + 
  coord_flip()

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM