Tigran Minasyan
Tigran Minasyan

Reputation: 85

Histogram not showing all x-axis labels in R

I have graphed a histogram but for some reason the x labels are partial. enter image description here

I want to have every year written on the x-axis. Here is my code:

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

Upvotes: 0

Views: 2190

Answers (2)

det
det

Reputation: 5232

You can try:

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

coord_flip is there because you will have a lot of 'long' labels on x-axis. If you dont want to flip you can rotate:

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

Upvotes: 1

Count Orlok
Count Orlok

Reputation: 1007

Try adding scale_x_continuous with the breaks argument:

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

Upvotes: 1

Related Questions