R - ggplot2 change x-axis values to non-log values

时光毁灭记忆、已成空白 提交于 2019-12-07 05:24:14

问题


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)

Answered...Final plot:


回答1:


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)))


来源:https://stackoverflow.com/questions/35262341/r-ggplot2-change-x-axis-values-to-non-log-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!