Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2, facet_grid, free scales?

Tags:

r

ggplot2

In the following example, how do I get the y-axis limits to scale according to the data in each panel?

mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()  

Neither of these will do it:

mt + facet_grid(. ~ cyl, scales="free") mt + facet_grid(. ~ cyl, scales="free_y") 
like image 892
hatmatrix Avatar asked Sep 10 '10 14:09

hatmatrix


People also ask

What is the function of Facet_grid () in Ggplot ()?

facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data.

What is the difference between Facet_wrap and Facet_grid?

While facet_grid shows the labels at the margins of the facet plot, facet_wrap creates a label for each plot panel.

What is faceting in Ggplot?

Faceting is the process that split the chart window in several small parts (a grid), and display a similar chart in each section. Each section usually shows the same graph for a specific group of the dataset. The result is usually called small multiple.


1 Answers

Perhaps it's because you have only one y axis, using your way. Did you try something like this?

mt + facet_grid(cyl ~ ., scales="free") 
like image 153
George Dontas Avatar answered Oct 10 '22 21:10

George Dontas