xlabel and ylabel for facet
I'm doing like this:
ggplot(IDPlotLn, aes(x=CO3, y=CRf)) +
xlab(xlabel) +
ylab(ylabel) +
opts(
axis.text.x = theme_text(size=10, face="plain", colour="black",vjust=1),
axis.text.y =开发者_C百科 theme_text(size=10, face="plain", colour="black", hjust=1)) +
scale_y_continuous(limits = c(-1.3 , 1.3), expand = c(0,0)) +
opts(panel.margin=unit(1, "cm")) +
geom_point() +
geom_smooth(method="lm",se=F) +
facet_wrap(~ ID, nrow=7, ncol=3, scales = "free") +
opts(strip.text.x = theme_text(size = 8))
I want to plot Xlabel and ylabel for each one of my facet, the same xlabel and ylabel. Like this I have only one xlabel and ylabel for all of the facet.
Is it possible?
Thank you for yours answer, I didn't know gridExtra.
But in this example, I'm faceting and I just want to make it more beautiful, it is the same xlabel and ylabel that I want to add for each panel. Because after for I want to choose several panels from all my panels, so it can be nice if I have already x and y label.
If you are trying to use different labels for the x and y axes when faceting then the correct answer is that you probably shouldn't be using facets. The entire point of faceting is that each panel shares the same x and y axis. So if you're labeling them differently, chances are you're misusing faceting.
What you probably want instead is to simply plot each panel separately and then arrange them in a grid. This can be easily done in ggplot2
with the help of the gridExtra
package:
dat <- data.frame(x = rep(1:5,3),
y = rnorm(15),
z = rep(letters[1:3],each = 5))
dat <- split(dat,dat$z)
p1 <- ggplot(dat[[1]],aes(x=x,y=y)) +
geom_point() +
labs(x = 'xlabel1',y='ylabel1')
p2 <- ggplot(dat[[2]],aes(x=x,y=y)) +
geom_point() +
labs(x = 'xlabel2',y='ylabel2')
p3 <- ggplot(dat[[3]],aes(x=x,y=y)) +
geom_point() +
labs(x = 'xlabel3',y='ylabel3')
library(gridExtra)
grid.arrange(p1,p2,p3)]
See ?grid.arrange
for more examples.
精彩评论