cha*_*win 1 r scale ggplot2 geom-bar
我正在使用这段代码:
ggplot2::ggplot(DATAFRAME, aes(x = as.factor(VARIABLE))) + ggplot2::geom_bar()
Run Code Online (Sandbox Code Playgroud)
绘制数据框 DATAFRAME 中变量 VARIABLE 每个级别的出现次数。然而,它是一个相当长的数据框,所以我希望计数以千为单位而不是单位。有人知道怎么做这个吗?
您可以使用自定义函数作为labels
. 只需将其添加到您的绘图中即可
+ scale_y_continuous(name = "Count (thousands)",
labels = function(y) y / 1000)
Run Code Online (Sandbox Code Playgroud)
对于可重现的示例:
ggplot(data.frame(x = 1:2, y = 3:4 * 1000)) +
geom_point(aes(x, y)) +
scale_y_continuous(
name = "Axis in thousands",
labels = function(x) x / 1000
)
Run Code Online (Sandbox Code Playgroud)
如果你想变得更奇特,你甚至可以粘贴"k"
到数字的末尾:
labels = function(x) paste0(x / 1000, "k")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3494 次 |
最近记录: |