Discussion:
Combine coord_fixed() and coord_flip()?
Ben Harrison
2013-05-21 05:38:35 UTC
Permalink
I am trying to change the aspect ratio of a particular plot, and the only
way I've worked out to do this is with coord_fixed(). If there are other
ways, then this question might be redundant!

The plot describes the changes in a variable (GR) with depth.
Depth being independent, I place it in x, but as per custom, we plot depth
on vertical axis.
I also need depth to be increasing from top to bottom:

ggplot(data=logs, aes(x=DEPTH, y=GR)) + geom_line() +
scale_x_reverse() + coord_flip()

This is fine, but the aspect ratio is unfettered.

last_plot() + coord_fixed(ratio=1)

Has the desired effect, but resets the flip, so that depth is again on the
horizontal axis. Is there a way to combine the two? I haven't been able to
figure it out.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Dennis Murphy
2013-05-21 15:57:31 UTC
Permalink
You can only use one coord_*() function on a given ggplot since it
changes the coordinate system after everything else has been done. To
change the aspect ratio, you can use the corresponding argument in the
theming system:

... + coord_flip() + theme(aspect.ratio = 1)

Untested in the absence of a reproducible example. If this doesn't
work, please provide one.

Dennis

On Mon, May 20, 2013 at 10:38 PM, Ben Harrison
Post by Ben Harrison
I am trying to change the aspect ratio of a particular plot, and the only
way I've worked out to do this is with coord_fixed(). If there are other
ways, then this question might be redundant!
The plot describes the changes in a variable (GR) with depth.
Depth being independent, I place it in x, but as per custom, we plot depth
on vertical axis.
ggplot(data=logs, aes(x=DEPTH, y=GR)) + geom_line() +
scale_x_reverse() + coord_flip()
This is fine, but the aspect ratio is unfettered.
last_plot() + coord_fixed(ratio=1)
Has the desired effect, but resets the flip, so that depth is again on the
horizontal axis. Is there a way to combine the two? I haven't been able to
figure it out.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
Ben Harrison
2013-05-21 22:51:44 UTC
Permalink
Thank you Dennis, that does work.

The docs at http://docs.ggplot2.org/current/theme.html do not mention this
at all.


Ben.
Post by Dennis Murphy
You can only use one coord_*() function on a given ggplot since it
changes the coordinate system after everything else has been done. To
change the aspect ratio, you can use the corresponding argument in the
... + coord_flip() + theme(aspect.ratio = 1)
Untested in the absence of a reproducible example. If this doesn't
work, please provide one.
Dennis
On Mon, May 20, 2013 at 10:38 PM, Ben Harrison
Post by Ben Harrison
I am trying to change the aspect ratio of a particular plot, and the
only
Post by Ben Harrison
way I've worked out to do this is with coord_fixed(). If there are other
ways, then this question might be redundant!
The plot describes the changes in a variable (GR) with depth.
Depth being independent, I place it in x, but as per custom, we plot
depth
Post by Ben Harrison
on vertical axis.
ggplot(data=logs, aes(x=DEPTH, y=GR)) + geom_line() +
scale_x_reverse() + coord_flip()
This is fine, but the aspect ratio is unfettered.
last_plot() + coord_fixed(ratio=1)
Has the desired effect, but resets the flip, so that depth is again on
the
Post by Ben Harrison
horizontal axis. Is there a way to combine the two? I haven't been able
to
Post by Ben Harrison
figure it out.
--
--
You received this message because you are subscribed to the ggplot2
mailing
Post by Ben Harrison
list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google
Groups
Post by Ben Harrison
"ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by Ben Harrison
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...