r - ggplot2: qplot facet axis scale free while preserving the grid -
r - ggplot2: qplot facet axis scale free while preserving the grid -
i have next plot (borrowed http://www.statmethods.net/advgraphs/ggplot2.html):
created next code:
library(ggplot2) # create factors value labels mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5), labels=c("3gears","4gears","5gears")) mtcars$am <- factor(mtcars$am,levels=c(0,1), labels=c("automatic","manual")) mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8), labels=c("4cyl","6cyl","8cyl")) q <- qplot(hp, mpg, data=mtcars, shape=am, color=am, size=i(3), facets=gear~cyl, xlab="horsepower", ylab="miles per gallon") print(q)
now i'd axis "scale better". illustration 3 gears column axis scaled range 10 25. still want preserve cyl-gears-grid , want 1 scale per column.
so next not expect:
q <- qplot(hp, mpg, data=mtcars, shape=am, color=am, size=i(3), xlab="horsepower", ylab="miles per gallon") q <- q + facet_wrap(facets=gear~cyl, scales="free_y") print(q)
is there way accomplish ggplot2?
if need 1 scale each column or row should utilize facet_grid()
instead of facet_wrap()
because facet_wrap()
each facet scales="free"
treated independently , aligned in number of columns set.
qplot(hp, mpg, data=mtcars, shape=am, color=am, size=i(3), xlab="horsepower", ylab="miles per gallon") + facet_grid(facets=gear~cyl, scales="free_y")
r plot ggplot2
Comments
Post a Comment