【发布时间】:2023-03-23 06:10:01
【问题描述】:
我有一个data.frame,它包含多个组:
set.seed(1)
df <- data.frame(group = sample(c("a","b"),200,replace = T),
n = round(runif(200,1,2)))
df$n <- as.integer(df$n)
我正在尝试使用ggplot2 的geom_histogram 显示group 的直方图:
library(ggplot2)
ggplot(data = df, aes(x = n)) + geom_histogram() + facet_grid(~group) + theme_minimal()
知道如何让ggplot2 用直方图汇总的整数而不是当前显示的数值来标记 x 轴刻度吗?
【问题讨论】:
-
+ scale_x_continuous(breaks = unique(df$n))
标签: r ggplot2 histogram axis-labels xticks