Dear Dieter,
I tried that. But it rescales one of the axis. The resulting graph is
still square. But now 1 cm Y-axis equal 2.5 cm on the X-axis. This seems
not te be the documented behaviour.
ggplot(ds, aes(x = x, y = y)) + geom_point() + coord_equal(ratio = 2/5)
>From sessionInfo()
R 2.9.0 on WinXP
ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.8 proto_0.3-8
-----Oorspronkelijk bericht-----
Regards,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry....@inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
Van: r-help-...@r-project.org [mailto:r-help-...@r-project.org]
Namens Dieter Menne
Verzonden: dinsdag 19 mei 2009 16:15
Aan: r-h...@stat.math.ethz.ch
Onderwerp: Re: [R] Coord_equal in ggplot2
ONKELINX, Thierry <Thierry.ONKELINX <at> inbo.be> writes:
>
> I'm plotting some points on a graph where both axes need to have the
> same scale. See the example below. Coord_equal does that trick but in
> this case it wastes a lot of space on the y-axis. Setting the limits
> of the y-axis myself was no avail.
>
> Any suggestions to solve this problem?
>
> library(ggplot2)
> ds <- data.frame(x = runif(1000, min = 0, max = 300000), y =
> runif(1000, min = 140000, max = 260000)) ggplot(ds, aes(x = x, y = y))
> + geom_point() + coord_equal() ggplot(ds, aes(x = x, y = y)) +
> geom_point() + coord_equal() + scale_x_continuous(limits = c(0,
> 300000)) + scale_y_continuous(limits = c(140000, 260000))
I think you need to set ratio in addition to cut off the extra space.
(Not tried)
>From Docs:
Equal scales. coord_equal ensures that the x and y axes have equal
scales: i.e.
1 cm along the x axis represents the same range of data as 1 cm along
the y axis. By default it will assume that you want a one-to-one ratio,
but you can change this with the ratio parameter. The aspect ratio will
also be set to ensure that the mapping is maintained regardless of the
shape of the output device. See the documentation of coord_equal() for
more details.
Dieter
______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
It does both. The aspect ratio needs to match the "scale" ratio,
otherwise you can resize the plot so that the scale ratio doesn't
match.
> ...one parameter, 'ratio', which specifies
> the ratio between the x and y scales. An aspect ratio of two means
> that the plot will be twice as high as wide. An aspection [sic] ratio
> of 1/2 means that the plot will be twice as wide as high. By
> default, the aspect.ratio of the plot will also be set to this value.
>
> The last sentence makes it sound as though the 'ratio' is distinct from the
> 'aspect.ratio', but the preceding sentence calls the 'ratio' the 'aspect
> ratio'. All very confusing.
>
> But as I understand the overall intent, coord_equal() is defined to give
> equal *scales* on the two axes. As a side-effect, it also sets aspect.ratio
> to 1 (why?). (aspect.ratio is an undocumented parameter to opts which
> apparently means the aspect ratio of the plot area and presumably does not
> change the scales).
Correct. See above for why.
> pp <- ggplot(data=data.frame(a=1:4,b=2^(1:4))) + geom_point(aes(x=a,y=b))
>
> This gives (correctly, I think) a square plot with x = -4..10 and y=2..16:
> pp + coord_equal()
>
> This gives (incorrectly, I think) a tall, narrow plot, and doesn't limit x
> to 0..5:
> pp + coord_equal() + xlim(0,5)
>
> This gives (correctly, I think) a square plot with equal scales:
> pp + coord_equal() + ylim(0,100)
>
> This gives (incorrectly, I think) a tall, narrow plot with unequal scales:
> pp + coord_equal() + opts(aspect.ratio = 10)
>
> This gives (incorrectly, I think) a square plot with equal scales
> (apparently coord_equal's *default* setting of aspect.ratio is overriding
> the *explicit* setting of aspect.ratio, which seems wrong):
> pp + opts(aspect.ratio = 10) + coord_equal()
If anyone could give me a comprehensive set of test cases (with all
combinations of setting x, y and ratio) and what they expect I could
come up with an algorithm, but the behaviour is currently poorly
defined because I don't really understand what people want/expect.
Hadley
Here are some examples and what I would expect them to do. I would suggest to split the ratio parameter into scale and aspect.
library(ggplot2)
ds <- data.frame(
x = runif(1000, min = 0, max = 300000),
y = runif(1000, min = 140000, max = 260000))
ggplot(ds, aes(x = x, y = y)) + geom_point() + coord_equal()
# a square plot with the same scale on both axis.
ggplot(ds, aes(x = x, y = y)) + geom_point() + coord_equal() + scale_x_continuous(limits = c(0, 300000)) + scale_y_continuous(limits = c(140000, 260000))
# a non square plot with the same scale on both axis
ggplot(ds, aes(x = x, y = y)) + geom_point() + coord_equal(scale = 2/5, aspect = 1)
# a square plot. 2 cm on the X-axis equals 5 cm on the Y-axis
ggplot(ds, aes(x = x, y = y)) + geom_point() + coord_equal(scale = 1, aspect = 2/5)
# a plot that is 2/5 times higher than wide. The scale on both axes is the same.
Best regards,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry....@inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: hadley wickham [mailto:h.wi...@gmail.com]
Verzonden: dinsdag 19 mei 2009 22:52
Aan: macr...@alum.mit.edu
CC: ggplot2; Dieter Menne; ONKELINX, Thierry
Onderwerp: Re: [R] Coord_equal in ggplot2
On Tue, May 19, 2009 at 11:44 AM, Stavros Macrakis <macr...@gmail.com> wrote:
Hadley
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer