ggplot2通过常数因子转换轴

ggplot2通过常数因子转换轴

本文介绍了ggplot2通过常数因子转换轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在ggplot2密度图(geom_density)中,我有以下y轴标签 0.000 0.005 0.010 0.015 0.020 ul> 将它们改为类似的正确方法是什么? 0 > 5 10 $ 15 $ 可能会在标签上自动添加10 ^ 3 x密度。在过去,我只是增加了我的数据并手动更改了标签,但在这种情况下,密度图为我生成了y轴数据。 I我知道我可以编写诸如 scale_y_continuous(trans =log10)之类的东西,但还没有找到任何办法来做一个简单的乘法常量,或者定义一个自定义转换。 解决方案您可以添加 scale_y_continuous(formatter ='formatter1000')与之前定义的以下函数: formatter1000 x * 1000 } 请注意,上面的答案是给出的一年半前的一个ggplot版本。使用ggplot的最新版本(0.9),上面的示例不起作用,请尝试如下所示: scale_y_continuous(labels = formatter1000) In a ggplot2 density plot (geom_density) I have the following y-axis labels0.0000.0050.0100.0150.020What is the correct way to change them to something like05101520possibly with the automatic adding of "10^3 x density" to the label. In the past I've just multiplied my data and manually changed the label, but in this case the y-axis data is generated for me by the density plot.I'm aware that I can write things like scale_y_continuous(trans="log10"), but have not found any way to do a simple multiplicative constant, or define a custom transform. 解决方案 You could add the scale_y_continuous(formatter='formatter1000') with the following function defined before:formatter1000 <- function(x){ x*1000}Please note, that the above answer was given one and a half year ago with a prior ggplot version. With the latest release (0.9) of ggplot the above example is not working, please try something like: scale_y_continuous(labels = formatter1000) 这篇关于ggplot2通过常数因子转换轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 16:33
查看更多