我有下面的資料框,我創建了一個箱線圖。我想格式化 y 軸和圖例中的數字,以便使用逗號或 .
df_long<-structure(list(WORDS = c("Comedy", "Education", "Entertainment",
"Film & Animation", "Gaming", "Howto & Style", "Music", "People & Blogs",
"Science & Technology", "Sports"), TOTALS = c(0, 943330388, 0,
0, 0, 543234645, 45831420, 0, 27301292, 160818771)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
p <- ggplot(df_long, aes(x = WORDS, y = TOTALS, fill = WORDS))
geom_boxplot()
p
theme_minimal()
theme(axis.text.x = element_text(angle = 90, vjust = 0.5,
hjust=1))
xlab("Industries")
ylab("Value") guides(fill=guide_legend(title="Industries"))
scale_y_continuous(formatter = comma) scale_fill_continuous(formatter = comma)
uj5u.com熱心網友回復:
一種方法是使用scales::comma.
注意我已洗掉scale_fill_continuous,因為這是不正確的:填充美學與離散變數有關:WORDS
library(ggplot2)
library(scales)
ggplot(df_long, aes(x = WORDS, y = TOTALS, fill = WORDS))
geom_boxplot()
theme_minimal()
theme(axis.text.x = element_text(angle = 90, vjust = 0.5,
hjust=1))
xlab("Industries")
ylab("Value")
guides(fill = guide_legend(title="Industries"))
scale_y_continuous(labels = comma)

由reprex 包于 2022-03-21 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446297.html
上一篇:動態合并帶后綴的xts物件
下一篇:如何檢查R中資料的凸性?
