删除 axis.titles in gg.gap () 地块
Remove axis.titles in gg.gap () plots
有人知道如何从 gg.gap() 图中删除 axis.title.y 吗?
我正在尝试使用 theme () 但它不起作用...
例如使用 gg.gap() 包示例:
我做了一个没有任何 y 和 x 轴标题的 ggplot("p" 图),但是当我在 gg.gap 中使用 "p" 在 y 轴上创建一个间隙时,轴标题再次出现。 .
data(mtcars)
library(ggplot2)
p<-ggplot(data = mtcars, aes(x = gear, fill = gear)) +geom_bar() +ggtitle("Number of Cars by Gear") +xlab("Gears") +
theme( axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank())
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
而且 theme() 都不起作用...
pgg + theme( axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank())
提前致谢!
这个很有趣。正如@teunbrand 提到的,您应该能够通过 scale_y_continuous(name="")
或我的偏好:name=NULL
来解决此问题。它在任何排列中都不起作用!
似乎可行的方法是使用 lab(y=...)
或 ylab()
将轴标题设置为 NULL
或 ""
。我认为这在您添加它的任何地方都有效,但似乎您需要在应用 gg.gap()
函数之前添加到图中:
# this doesn't work
p <- p + scale_y_continuous(NULL)
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg
# this doesn't work either
pgg + scale_y_continuous(NULL)
# this apparently won't work
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg + ylab(NULL)
# this works
p <- p + ylab(NULL)
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg
有人知道如何从 gg.gap() 图中删除 axis.title.y 吗? 我正在尝试使用 theme () 但它不起作用...
例如使用 gg.gap() 包示例: 我做了一个没有任何 y 和 x 轴标题的 ggplot("p" 图),但是当我在 gg.gap 中使用 "p" 在 y 轴上创建一个间隙时,轴标题再次出现。 .
data(mtcars)
library(ggplot2)
p<-ggplot(data = mtcars, aes(x = gear, fill = gear)) +geom_bar() +ggtitle("Number of Cars by Gear") +xlab("Gears") +
theme( axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank())
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
而且 theme() 都不起作用...
pgg + theme( axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.x = element_blank(),
axis.text.x = element_blank())
提前致谢!
这个很有趣。正如@teunbrand 提到的,您应该能够通过 scale_y_continuous(name="")
或我的偏好:name=NULL
来解决此问题。它在任何排列中都不起作用!
似乎可行的方法是使用 lab(y=...)
或 ylab()
将轴标题设置为 NULL
或 ""
。我认为这在您添加它的任何地方都有效,但似乎您需要在应用 gg.gap()
函数之前添加到图中:
# this doesn't work
p <- p + scale_y_continuous(NULL)
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg
# this doesn't work either
pgg + scale_y_continuous(NULL)
# this apparently won't work
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg + ylab(NULL)
# this works
p <- p + ylab(NULL)
pgg <- gg.gap(plot=p,segments=c(5,10),tick_width = c(1,10),ylim=c(0,50))
pgg