相关疑难解决方法(0)

Cowplot让ggplot2主题消失/如何查看当前的ggplot2主题,并恢复默认?

我最近安装了这个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)

r ggplot2 cowplot

15
推荐指数
1
解决办法
3723
查看次数

ggplot2问题与方面和关闭剪辑

过去可以通过关闭裁剪功能将文本放置在绘图边距上。在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)

r ggplot2

5
推荐指数
1
解决办法
1211
查看次数

右对齐ggplot2中的旋转轴标题

如何将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)

在此输入图像描述

r ggplot2

4
推荐指数
1
解决办法
636
查看次数

标签 统计

ggplot2 ×3

r ×3

cowplot ×1