mjhendrickson/Learning-R

Adjust x-axes for integers to show only whole numbers. (e.g. 2012, 2013, etc., not 2011.5, 2012.0, 2012.5 etc.)

mjhendrickson opened this issue · 4 comments

ggplot(data = HxMx) + geom_bar(mapping = aes(x = year)) + scale_y_continuous(name = " ", labels = comma) + theme(axis.title.x = element_blank()) + labs(title = "Year")
Produces an x axis with decimal places. Change this to whole numbers.
image

A possible fix is to set the breaks manually. But this isn't ideal as it isn't generalizable.
Ex:
ggplot(data = HxMx) + geom_bar(mapping = aes(x = year)) + scale_x_continuous(name = " ", breaks = c(2012, 2013)) + scale_y_continuous(name = " ", labels = comma) + theme(axis.title.x = element_blank()) + labs(title = "Year")
image

Closing for now as this works and unable to find an automated method.

You can use the best ggplotAssist package in rstudio

Thanks @amirhmstu for the pointer. I'm giving it a look, but I'm having issues with it rendering appropriately. I think it may have something to do with my browser extensions. I'll keep playing around with it. Either way, it's a neat tool to help understand how the pieces all come together.