Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute values in axis labels

Tags:

r

ggplot2

In the following graphic, the values in the x axis represent distances, where I coloured by group, so for group A the distances are represented to the right, while for group B the distances are represented to the left (had to make them negative to plot like this). Is there a way to represent the values to the left of 0 as positive (absolute value)? To be clear, instead of -20, -40, -60, -80, I would like to show, to the left of 0: 20, 40, 60 and 80.

enter image description here

like image 778
daniellga Avatar asked Jan 25 '26 17:01

daniellga


1 Answers

You can pass the abs() function to the labels argument of scale_x_continuous():

... + scale_x_continuous(labels = abs)
like image 51
Ritchie Sacramento Avatar answered Jan 27 '26 07:01

Ritchie Sacramento



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!