bg = ggplot2中的“n”

时间:2015-10-30 14:12:31

标签: r ggplot2 axis

ggplot2中是否有一种方法可以在正常的R图形中使不在一起的轴如bty =“n”?

像这样:

https://www.google.es/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0CAcQjRxqFQoTCMrel4Gv6sgCFURuFAodNm8DQg&url=http%3A%2F%2Fwww.sthda.com%2Fenglish%2Fwiki%2Fimpressive-package-for-3d-and-4d-graph-r-software-and-data-visualization&bvm=bv.106379543,d.d24&psig=AFQjCNH_hFG9OcD1gDwigFZ1zD-tSpNeCA&ust=1446300403084347

谢谢

3 个答案:

答案 0 :(得分:3)

theme_classic会产生与上述

非常相似的内容
ggplot(faithful, aes(x=eruptions, y=waiting)) + 
  geom_point(shape=21) +
  theme_classic()

enter image description here

答案 1 :(得分:3)

它有点笨拙,但你可以通过在适当的位置抑制轴和用段注释来做到这一点:知道ggplot将放置x / y坐标为{的元素是有用的。 {1}}位于情节的左下角...

-Inf

我不知道更简单/更自动的方式;我不认为一个存在,但希望我错了。

library("ggplot2") axrange <- list(y=c(50,90),x=c(2,5)) g0 <- ggplot(faithful, aes(x=eruptions, y=waiting)) + geom_point(shape=21) g0 + theme_classic()+ theme(axis.line.y=element_blank(),axis.line.x=element_blank())+ annotate("segment",x=-Inf,xend=-Inf,y=axrange$y[1],yend=axrange$y[2])+ annotate("segment",y=-Inf,yend=-Inf,x=axrange$x[1],xend=axrange$x[2]) 包中的Tufte主题提供了另一种最小图,但不是你想要的......

ggthemes

答案 2 :(得分:0)

为解决这个问题而道歉,但我认为重新审视这个问题的人可能会知道 ggh4x 有一个截断的轴指南可以做到这一点。 (免责声明,我写了那个包)。下面的例子:

library(ggplot2)
library(ggh4x)

ggplot(faithful, aes(eruptions, waiting)) +
  geom_point() +
  guides(x = "axis_truncated", y = "axis_truncated") +
  theme(axis.line = element_line(colour = "black"))

reprex package (v0.3.0) 于 2021 年 3 月 22 日创建