簡體   English   中英

直方圖未顯示 R 中的所有 x 軸標簽

[英]Histogram not showing all x-axis labels in R

我繪制了一個直方圖,但由於某種原因,x 標簽是部分的。 在此處輸入圖像描述

我想讓每一年都寫在 x 軸上。 這是我的代碼:

ggplot(video_games, aes(x = Year)) + geom_histogram(stat = 'count') + lims(x = c(1995, 2017))

嘗試使用breaks參數添加scale_x_continuous

ggplot(...) +
  ... +
  scale_x_continuous(breaks = 1995:2016)

你可以試試:

ggplot(video_games, aes(x = year)) + 
  geom_bar() +
  scale_x_continuous(breaks = unique(video_games$year)) +
  coord_flip()

coord_flip在那里,因為您將在 x 軸上有很多“長”標簽。 如果你不想翻轉,你可以旋轉:

theme(axis.text.x = element_text(angle = 90, vjust = 0.5))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM