[R] Query on R plot : Unequispaced label on x-axis
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Jul 24 20:52:49 CEST 2013
On 24/07/2013 10:06 AM, ritwik_r at isical.ac.in wrote:
> Dear R users,
>
> I want to plot a one variable continuous function f(x) vs x, x=[0,1]. Say
> for example: f(x)= x^2. Now, using the command plot(f~x) I will get a
> curve where the range of x-axis is [0,1] with all equispaced label. But, I
> need something else, and that is: my curve will be such that 80% on x-axis
> the range would be [0,0.5] and the rest 20% would contain [0.5,1]. Let me
> draw informally here. Say, the line below is my x-axis in graph and my
> plotting points are like:
>
>
>
> ________________________________________
> 0 0.01 0.1 0.5 1
>
> Any help or suggestion will be highly appreciable.
Construct a function pos(x) that takes the x values and converts them
into the position on the axis that you want. For example,
pos <- function(x) log(x + 0.001)
plot(pos(x), y, xaxt="n")
will plot the transformed values, with no x axis labels. To get the
labels, use
xvals <- c(0, 0.01, 0.1, 0.5, 1) # or whatever makes sense
axis(1, at=pos(xvals), labels=xvals)
Duncan Murdoch
More information about the R-help
mailing list