refactored code to set x and y spacing for ticks