我正在嘗試編輯 Y 軸刻度以表示 Id 的行數。需要在規模上顯示的數字是數百萬。我需要縮寫數字才能在可視化中看到它。
ggplot(sleeptocalories1, aes(Id,TotalCalories)
geom_col(fill="steelblue")
theme(axis.text.x = element_text(angle = 90))
theme(axis.text.y = element_text(angle = 45))
uj5u.com熱心網友回復:
我喜歡scales::label_number_si():
ggplot(data.frame(x = 1:5, y = 10^(2:6)), aes(x, y))
geom_col()
scale_y_continuous(labels = scales::label_number_si())

根據您的資料,它可能是:
ggplot(sleeptocalories1, aes(Id,TotalCalories)
geom_col(fill="steelblue")
theme(axis.text.x = element_text(angle = 90))
theme(axis.text.y = element_text(angle = 45))
scale_y_continuous(labels = scales::label_number_si())
uj5u.com熱心網友回復:
labels一種選擇是通過 的引數將標簽轉換為數百萬scale_y_continuous。
使用一些假的隨機示例資料:
set.seed(123)
sleeptocalories1 <- data.frame(
Id = 1:10,
TotalCalories = runif(10, 86, 12e6)
)
library(ggplot2)
ggplot(sleeptocalories1, aes(Id, TotalCalories))
geom_col(fill = "steelblue")
scale_y_continuous(labels = ~ .x / 1e6)
theme(axis.text.x = element_text(angle = 90))
theme(axis.text.y = element_text(angle = 45))

uj5u.com熱心網友回復:
該scales庫可以幫助格式化繪圖的比例。科學記數法是縮寫。
library(scales)
library(ggplot2)
demo_continuous(c(0, 1e9), labels = label_number_auto())

可能不適合此應用程式,但日志中斷也是可能的
demo_log10(c(1, 1e5), labels = label_log())

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/527525.html
標籤:rggplot2y轴
