You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MATLAB中loglog函数的R语言等价实现:如何绘制带原始数值刻度标签的双对数图

Equivalent of MATLAB's loglog in R

Absolutely! You don’t need to manually compute log values and tweak axes—R has built-in tools that mimic MATLAB’s loglog perfectly, creating a log-scaled plot while displaying your original numeric values as tick labels.

Base R Solution

The simplest approach in base R uses the log argument in the plot() function. Setting log = "xy" enables logarithmic scaling for both axes, and automatically labels ticks with your actual data values (not their log-transformed equivalents):

# Sample data
x <- c(0.5, 10, 45, 100)
y <- c(2, 20, 90, 200) # Example proportional y-values

# Create log-log plot with original value labels
plot(x, y, log = "xy", main = "Log-Log Plot (Base R)", xlab = "X", ylab = "Y")

This produces a plot identical in behavior to MATLAB’s loglog: the axes are logarithmically scaled, but tick marks show your raw data points (like 0.5, 10, 45) instead of log₁₀ values.

ggplot2 Alternative

If you prefer using the ggplot2 package, you can achieve the same result with logarithmic scale functions that preserve original value labels:

library(ggplot2)

# Create ggplot log-log plot
ggplot(data.frame(x, y), aes(x, y)) +
  geom_point() +
  geom_line() +
  scale_x_log10() +
  scale_y_log10() +
  labs(title = "Log-Log Plot (ggplot2)", x = "X", y = "Y")

Both methods eliminate the need for the manual axis setup you were using before. The base R approach is the most direct for MATLAB users transitioning to R.

Content of the question originates from Stack Exchange, asked by Orestis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 14:58:10