我最近安装了这个cowplot包.然而,在这样做之后,我注意到我的ggplots缺少他们的背景和网格线theme_grey()!
创建上述每个图的代码是:
result_df %>%
ggplot(aes_string(x = 'p', y = 'r')) +
# theme_grey() + # uncomment this line to produce plot on right
geom_point(aes(group = c), size = 0.5) +
geom_line(aes(group = c), size = 0.2, linetype = 'dotted') +
theme(axis.text.x=element_text(angle = 90, hjust = 1, vjust = 0.5)) +
facet_grid(b ~ e, scales = "free_y") +
scale_x_continuous(breaks = seq(0, 10, 2))
Run Code Online (Sandbox Code Playgroud)
没有明确调用+ theme_grey(),我得到左边的情节.
这里发生了什么?我以为那theme_grey()是默认的.如何查看我的默认主题是什么?
这是我的一个片段sessionInfo():
R version 3.3.2 (2016-10-31) …Run Code Online (Sandbox Code Playgroud) 过去可以通过关闭裁剪功能将文本放置在绘图边距上。在ggplot2_2.2.0中,在使用构面的图中似乎不再可行(但如果不使用构面,则仍然可行)。我在这里发布了一个问题,但尚未解决。在此期间,任何解决方法的想法将不胜感激!
这是一个最小的(非工作)示例:
library(ggplot2)
library(grid)
df.plot = data.frame(x = 1, y = 1, facet = 'facet', stringsAsFactors = F)
df.text = data.frame(x = 1, y = -0.3, label = 'test', facet = 'facet', stringsAsFactors = F)
p = ggplot(df.plot,aes(x = x, y = y))+
facet_grid(~facet)+ # 'test' is only printed outside of the plot if faceting is turned off
geom_point()+
geom_text(data = df.text,aes(x=x,y=y,label=label))+
coord_cartesian(xlim = c(0, 2),ylim=c(0,2),expand=F)+
theme(plot.margin=unit(c(2,2,2,2),"cm"))
gt = ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] = "off"
grid.draw(gt)
Run Code Online (Sandbox Code Playgroud) 如何将Y轴标题("Species")与轴标签(三个物种名称)右对齐,以使轴标题靠近灰色面板?hjust似乎没有影响到这个位置.
library(ggplot2)
ggplot(iris,
aes(x = Species,
y = Sepal.Width)) +
geom_boxplot() +
labs(x = "Species",
y = "Sepal Width") +
coord_flip() +
theme(axis.title.y = element_text(angle = 0, hjust = 0))
Run Code Online (Sandbox Code Playgroud)