[R] plot control
Michael Dondrup
michael.dondrup at cebitec.uni-bielefeld.de
Mon Apr 24 11:05:11 CEST 2006
Hi,
it's not quite clear to me, what you are trying to accomplish with this. You
are referring to quantiles (you means quartiles in your case?,
see ?quantile ). So, are you trying to compare theoretical quantiles of a
distribution to the empirical quantiles? Or are you just trying to split the
left axes into 4 ticks? For the first case, try something like:
> y <- rnorm(100)
> y.right.axisticks <- quantile(y)
> y.left.ticks <- qnorm(c(0.25,0.5,0.75)) #makes no sense to compare with
> # theor. quantiles of uniform distribution, right? ;)
> plot(y,yaxt='n')
> axis(2,at=y.left.ticks,labels=round(y.left.ticks,3))
> axis(4,at=y.right.axisticks,labels=round(y.right.axisticks,3))
or for the latter:
> yrange <- range(y)
> y.left.ticks <- seq(yrange[1], yrange[2], (yrange[2] - yrange[1])/4)
> plot(y,yaxt='n')
> axis(2,at=y.left.ticks,labels=round(y.left.ticks,3))
> axis(4,at=y.right.axisticks,labels=round(y.right.axisticks,3))
is that, what you thought of?
see also:
?qqplot
for another way to compare quantiles
cheers
Am Monday 24 April 2006 08:53 schrieb Alexander Nervedi:
> Dear R gurus,
>
> I'd like to plot a distribution with the tickmarks always at the quantiles
> of the y-axis, as opposed to the quantiles of the distribution I am
> plotting. plot seems to place these ticks based on some calculations that I
> cant see (?plot doesnt show the innards of plot).
>
> Below is some functional code, but the tick marks are placed unattractively
> since I am referencing the quantiles of the distribution. I'd ideally like
> the tickmarks to be able to reference fixed points on the y-axis and the
> show the associted values.
>
> I'd be very grateful for ideas, suggestion and leads.
>
> - alex.
>
> # some code
>
> y1<-rnorm(100)
> y2<-runif(100)
> x <-1:100
>
> l <-length(y1)
> mat<-scale(cbind(y1,y2))
>
> plot(x, mat[,1], col = "blue", yaxt = "n", ylab="")
> axis(2, at = sort(mat[,1])[c(0.25*l,0.5*l,0.75*l)],
> labels = round(sort(y1)[c(0.25*l, 0.5*l,0.75*l)],2))
>
> points(x, mat[,2], col = "red")
> axis(4, at = sort(mat[,2])[c(0.25*l,0.4*l,0.75*l)],
> labels = round(sort(y2)[c(0.25*l, 0.5*l,0.75*l)],2))
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list