Search code examples
rggplot2geom-bar

ggplot2's geom_bar() not showing default x axis ticks


As a simple example I am going to use the diamonds data:

data(diamonds)

ggplot(diamonds, aes(x = clarity, y = carat, fill = cut)) +
  geom_bar(stat = "identity")

This will give me the following output, where the x axis is not annotated:

missing x- and y-axis labels

How do I make the values of the x- and y-axis appear? I have been searching wide and far and haven't yet found a solution...

For my real dataset, my x-axis values are discrete, and using scale_x_discrete() does not change the outcome.

Thank in advance!


Solution

  • Your code works fine, I believe you must update ggplot2 and start a new R session:

    data(diamonds)
    
    ggplot(diamonds, aes(x = clarity, y = carat, fill = cut)) +
      geom_bar(stat = "identity")
    

    enter image description here