这里是一些随机生成的样本数据:
[数据信息:每天访问特定商店的客户数量,跨不同分支]
library(tidyverse)
library(ggplot2)
make_skewed_data <- function(n = 20){
round(rlnorm(n = n, meanlog = 0.3, sdlog = 0.5)*1000, 0)
}
num_customers <-
c(make_skewed_data(50), make_skewed_data(50), make_skewed_data(50),
make_skewed_data(50), make_skewed_data(50), make_skewed_data(50))
DF <- tibble(day = paste0("day", seq(1:50)) %>% rep(6),
branch = paste0("branch", rep(seq(1:6), each = 50)),
num_customers = num_customers)
# > DF
# # A tibble: 300 × 3
# day branch num_customers
# <chr> <chr> <dbl>
# 1 day1 branch1 1097
# 2 day2 branch1 1658
# 3 day3 branch1 1372
# 4 day4 branch1 1448
# 5 day5 branch1 1501
# 6 day6 branch1 2036
# 7 day7 branch1 2599
# 8 day8 branch1 1049
# 9 day9 branch1 1142
# 10 day10 branch1 1105
# # … with 290 more rows
以下代码使用
facet_wrap
. 生成直方图集合
DF %>%
ggplot(aes(x = num_customers)) +
geom_histogram(bins = 40) +
theme_bw() +
facet_wrap(~branch)
目前
想要的解决方案
试过
scale_x_continuous(limits = c(min, max))
可以用感谢任何帮助:)