Dear all, 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)) 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.Onkelinx at 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 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.
If you use coord_equal on data where the range on the x-axis is larger than the range on the y-axis, then of course you'll observe extra space on the y-axis. What did you expect? Also, this post may be better suited to the ggplot2 mailing list: http://had.co.nz/ggplot2/ On Tue, May 19, 2009 at 7:17 AM, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:> Dear all, > > 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)) > > 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.Onkelinx at 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 > > > 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-help at 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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~
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