在ggplot中,为什么必须单独将axis.text.x和axis.text.y设置为element_blank()而不是仅仅是axis.text?

发布于 2025-02-12 20:47:47 字数 732 浏览 0 评论 0原文

此代码产生此图:

ggplot(mtcars, aes(x = cyl, y = mpg))+
    geom_line()+
    theme(axis.text = element_blank())

”在此处输入图像描述”

似乎axis.text参数没有 工作。为了使其正常工作,需要做到这一点:

ggplot(mtcars, aes(x = cyl, y = mpg))+
    geom_line()+
    theme(axis.text.x = element_blank(),
          axis.text.y = element_blank())

“在此处输入图像说明”

我的问题是为什么?

This code produces this plot:

ggplot(mtcars, aes(x = cyl, y = mpg))+
    geom_line()+
    theme(axis.text = element_blank())

enter image description here

Where it seems that axis.text argument doesn't work. In order to make it work, one needs to do this:

ggplot(mtcars, aes(x = cyl, y = mpg))+
    geom_line()+
    theme(axis.text.x = element_blank(),
          axis.text.y = element_blank())

enter image description here

My question is why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云 2025-02-19 20:47:47

axis.text根据文档:

沿轴(element_text;从文本继承)tick标签

时,当我运行您的代码时,它确实有效:

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.2
ggplot(mtcars, aes(x = cyl, y = mpg))+
  geom_line()+
  theme(axis.text = element_blank())

“

在20222222222222222222222年创建-07-05 by reprex软件包(v2.0.1)

axis.text according to document:

tick labels along axes (element_text; inherits from text)

When I run your code it does work:

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.2
ggplot(mtcars, aes(x = cyl, y = mpg))+
  geom_line()+
  theme(axis.text = element_blank())

Created on 2022-07-05 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文