Setting ylim and xlim in facet_grid

2,817 views
Skip to first unread message

Vikas Rawal

unread,
Sep 13, 2016, 7:04:04 AM9/13/16
to ggp...@googlegroups.com
I am using the following code to make a graph

-----------

ggplot(data1,aes(x=Year,y=value,group="country_name"))->p
p+facet_grid(apy~country_name,scales="free_y")->p
p+theme(axis.text.x = element_text(angle=90, vjust=0.5, size=10),axis.title.y=element_blank(),strip.text.y=element_text(size=10))

——————

The dataframe data1 has variables Year, value, country_name and apy. Variable apy takes three values: “Area", “Yield" and “Production". The scales of Area, Yield and Production are different. To deal with this, I would like to explicitly specify the limits of the scales for Area, Yield and Production in the facet_grid command. These would have to be different for each of them.

How could I possibly do that? Or is there any other way in ggplot to specify (different) limits of scales in different facets.

Vikas

Pete St Marie

unread,
Sep 13, 2016, 9:04:42 AM9/13/16
to ggplot2
This SO question has a hack that works:http://stackoverflow.com/questions/4276218/how-do-you-set-different-scale-limits-for-different-facets

Here is the (closed) issue on the ggplot2 github that looks at the issue: https://github.com/hadley/ggplot2/issues/187

--pete 

Brian

unread,
Sep 13, 2016, 12:35:31 PM9/13/16
to ggplot2
You may want finer control, but...
I don't think there is an issue.
You could try:

scales="free"

you could also try reordering the facet:

country_name~apy

I prefer to let the data speak for themselves. The default extension of
the plot margins make sense. Your code looks fine (except for spaces
etc.). Maybe I don't understand the problem.
> --
> --
> 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 ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> 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+u...@googlegroups.com
> <mailto:ggplot2+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages