Learn R Programming

RgoogleMaps (version 1.5.1)

updateusr: Updates the 'usr' coordinates in the current plot.

Description

For a traditional graphics plot this function will update the 'usr'

coordinates by transforming a pair of points from the current usr

coordinates to those specified.

Usage

updateusr(x1, y1 = NULL, x2, y2 = NULL)

Value

An invisible list with the previous 'usr' coordinates from par.

Arguments

x1

The x-coords of 2 points in the current 'usr' coordinates, or anything that can be passed to xy.coords.

y1

The y-coords of 2 points in the current 'usr' coordinates, or an object representing the points in the new 'usr' coordinates.

x2

The x-coords for the 2 points in the new coordinates.

y2

The y-coords for the 2 points in the new coordinates.

Author

Markus Loecher

Details

Sometimes graphs (in the traditional graphing scheme) end up with usr

coordinates different from expected for adding to the plot (for

example barplot does not center the bars at integers). This

function will take 2 points in the current 'usr' coordinates and the

desired 'usr' coordinates of the 2 points and transform the user

coordinates to make this happen. The updating only shifts and scales

the coordinates, it does not do any rotation or warping transforms.

If x1 and y1 are lists or matricies and x2 and

y2 are not specified, then x1 is taken to be the

coordinates in the current system and y1 is the coordinates in

the new system.

Currently you need to give the function exactly 2 points in each

system. The 2 points cannot have the same x values or y values in

either system.

Examples

Run this code


tmp <- barplot(1:4)


updateusr(tmp[1:2], 0:1, 1:2, 0:1)


lines(1:4, c(1,3,2,2), lwd=3, type='b',col='red')





# update the y-axis to put a reference distribution line in the bottom


# quarter





tmp <- rnorm(100)


hist(tmp)


tmp2 <- par('usr')


xx <- seq(min(tmp), max(tmp), length.out=250)


yy <- dnorm(xx, mean(tmp), sd(tmp))


updateusr( tmp2[1:2], tmp2[3:4], tmp2[1:2], c(0, max(yy)*4) )


lines(xx,yy)





Run the code above in your browser using DataLab