7

I am plotting some payment distribution information and I aggregated the data after scaling it to log-normal (base-e). The histograms turn out great but I want to modify the x-axis to display the non-log equivalents.

My current axis displays [0:2.5:10] values Alternatively, I would like to see values for exp(2.5), exp(5), etc.

Any suggestions on how to accomplish this? Anything I can add to my plotting statement to scale the x-axis values? Maybe there's a better approach - thoughts?

Current code:

ggplot(plotData, aes_string(pay, fill = pt)) + geom_histogram(bins = 50) + facet_wrap(~M_P)

enter image description here

Answered...Final plot: enter image description here

4
  • Is this solved if you exponentiate the data and then log-scale the x-axis? Commented Feb 8, 2016 at 4:28
  • @josliber applying "+scale_x_log10()" is limiting. What if you want scale using a distribution using a different log base? Commented Feb 8, 2016 at 5:33
  • @NikolayRodionov If you look at the documentation of scale_x_log10 you'll see that it is just a convenience function with a specific trans argument to scale_x_continuous. You can use whatever transformation you'd like - logarithm of any base, or anything else. Commented Feb 8, 2016 at 5:59
  • @Gregor your right, thanks. Still running into the same issue though -- if I use scale_x_log10() the x axis values are still 1 to 10. Any way to change the x values to the 10^x equivalents? My goal is to keep the original axis value labels while maintaining the log grouping. Commented Feb 8, 2016 at 6:05

1 Answer 1

7

Not sure if this is exactly what you are after but you can change the text of the x axis labels to whatever you want using scale_x_continuous.

Here's without:

ggplot(data = cars) + geom_histogram(aes(x = speed), binwidth = 1)

Here's with:

ggplot(data = cars) + geom_histogram(aes(x = speed), binwidth = 1) +
  scale_x_continuous(breaks=c(5,10,15,20,25), labels=c(exp(5), exp(10), exp(15), exp(20), exp(25)))
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Worked out great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.