小编Mic*_*Lee的帖子

ggplot2 - 在轴线上自定义 grob

我试图在 ggplot2 中生成一个轴线中断(轴线上有一个白色段),但遇到了一些问题。

使用内容丰富的帖子annotate-ggplot-with-an-extra-tick-and-label我能够在给定位置生成自定义 grobs,同时还关闭面板以在绘图区域外“绘制”。

我也熟悉其他包,例如plotrix并且能够在 base 中复制断轴,但最重要的是我有兴趣了解为什么我创建的轴不会覆盖线。下面是一些示例代码:

library(ggplot2) # devtools::install_github("hadley/ggplot2")
library(grid)
library(scales)


data("economics_long")
econ <- economics_long
econ$value01 <- (econ$value01/2)
x <- ggplot(econ, aes(date, value01,group=1)) + scale_y_continuous(labels=c(0.0,0.1,0.2,0.3,0.4,0.5,1.0), breaks=c(0.0,0.1,0.2,0.3,0.4,0.5,0.6),limits = c(0,.6),expand = c(0, 0)) +
  geom_smooth(colour="deepskyblue", show.legend = TRUE ) + theme_bw()

theme_white <- theme(panel.background=element_blank(),
                     panel.border=element_rect(color="white"),
                     plot.margin = unit(c(.2, 0, .2, .2), "cm"),
                     panel.grid.major.y=element_blank(),
                     panel.grid.major.x=element_blank(),
                     panel.grid.minor.x=element_blank(),
                     panel.grid.minor.y=element_blank(),
                     axis.title.y = element_blank(),
                     axis.line.x=element_line(color="gray", size=1),
                     axis.line.y=element_line(color="gray", size=1),
                     axis.text.x=element_text(size=12),
                     axis.text.y=element_text(size=12),
                     axis.ticks=element_line(color="gray", size=1),
                     legend.position="none"
)
x <- x + theme_white


gline = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

标签 统计

ggplot2 ×1

r ×1