我有我正在使用ggplot
's绘制的数据facet_grid
:
我的数据:
species <- c("spcies1","species2")
conditions <- c("cond1","cond2","cond3")
batches <- 1:6
df <- expand.grid(species=species,condition=conditions,batch=batches)
set.seed(1)
df$y <- rnorm(nrow(df))
df$replicate <- 1
df$col.fill <- paste(df$species,df$condition,df$batch,sep=".")
我的情节:
integerBreaks <- function(n = 5, ...)
{
library(scales)
breaker <- pretty_breaks(n, ...)
function(x){
breaks <- breaker(x)
breaks[breaks == floor(breaks)]
}
}
library(ggplot2)
p <- ggplot(df,aes(x=replicate,y=y,color=col.fill))+
geom_point(size=3)+facet_grid(~col.fill,scales="free_x")+
scale_x_continuous(breaks=integerBreaks())+
theme_minimal()+theme(legend.position="none",axis.title=element_text(size=8))
显然标签很长并且在图中很乱,所以我想知道是否有办法在ggplot
对象(p
)或gtable
///对象gTree
()中编辑这些标签grob
。gDesc
ggplotGrob(p)
我知道获得更好标签的一种方法是在创建对象labeller function
时使用,ggplot
但在我的情况下,我专门寻找一种在ggplot
创建对象后编辑构面标签的方法。