英文:
How to plot wide range data in bi-symmetric logarithmic scale in R?
问题
I have a large dataset need to be displayed in log-scale. But a log transformation could loss the 0 and negative values. I found this figure in literature this kind of symmetric logarithmic scale is just what I need.
对于大型数据集,需要在对数刻度上显示。但对数转换可能会丢失0和负值。我在文献中找到了这张图,这种对称对数刻度正是我所需要的。
The pseudolog10_trans function is R package "ggallin" is not a solution.
R包“ggallin”中的pseudolog10_trans函数并不是一个解决方案。
I found a solution in Matlab: https://www.mathworks.com/matlabcentral/answers/292499-how-can-i-plot-negative-value-with-log-scale, how can I plot that in R that include all positive, negative and zero values in log-transformed scale?
我在Matlab中找到了一个解决方案:https://www.mathworks.com/matlabcentral/answers/292499-how-can-i-plot-negative-value-with-log-scale,如何在R中绘制这种图形,包括所有正数、负数和零值在对数变换刻度上?
Mathematical reference: https://kar.kent.ac.uk/32810/2/2012_Bi-symmetric-log-transformation_v5.pdf
数学参考资料:https://kar.kent.ac.uk/32810/2/2012_Bi-symmetric-log-transformation_v5.pdf
英文:
I have a large dataset need to be displayed in log-scale. But a log transformation could loss the 0 and negative values. I found this figure in literature this kind of symmetric logarithmic scale is just what I need.
Figure in bi-symmetric logarithmic scale
The pseudolog10_trans function is R package "ggallin" is not a solution.
I found a solution in Matlab: https://www.mathworks.com/matlabcentral/answers/292499-how-can-i-plot-negative-value-with-log-scale, how can I plot that in R that include all positive, negative and zero values in log-transformed scale?
Mathematical reference: https://kar.kent.ac.uk/32810/2/2012_Bi-symmetric-log-transformation_v5.pdf
答案1
得分: 0
定义一个函数,将输入转换为带符号对数并使用自定义坐标轴绘制。不使用任何包。
x <- c(-2000, -200, 20, 20, 200, 2000) # 测试输入
signed_log <- function(x) ifelse(x == 0, 0, sign(x) * log(abs(x)))
plot(signed_log(x), yaxt = "n", xlab = "", ylab = "", type = "o")
b <- c(-1000, -100, -10, 0, 10, 100, 1000)
axis(2, signed_log(b), b)
英文:
Define a function to convert to signed log and plot the input with a custom axis. No packages are used.
x <- c(-2000, -200, 20, 20, 200, 2000) # test input
signed_log <- function(x) ifelse(x == 0, 0, sign(x) * log(abs(x)))
plot(signed_log(x), yaxt = "n", xlab = "", ylab = "", type = "o")
b <- c(-1000, -100, -10, 0, 10, 100, 1000)
axis(2, signed_log(b), b)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论