如何删除y.axis面板边框?

时间:2020-04-14 14:51:21

标签: r ggplot2

这是我的代码

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_clean() 

我要删除y轴黑线。这是我想要的结果 enter image description here

最佳,

2 个答案:

答案 0 :(得分:0)

使用以下代码

library(ggthemes)

ggplot(mtcars, aes(mpg, hp)) + 
  geom_point() + theme_hc() + 
  theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

如果您想根据自己的密码给出答案,

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  theme_clean()+
  theme(axis.line.y = element_blank(), axis.line.x = element_line(), plot.background=element_blank())

enter image description here

答案 1 :(得分:0)

尝试一下(使用theme_classic,这有点接近您想要的结果,但是同时具有x和y轴线):

ggplot(mtcars, aes(mpg, hp)) + 
    geom_point() + theme_classic() +
    theme(axis.line.y = element_blank(), axis.line.x = element_line())

enter image description here

如果键入theme_classic(不带括号),则可以看到用于创建该主题的所有theme元素。请注意,经典主题已应用axis.line,该主题同时创建了x和y轴线。如果您尝试仅 指定axix.line.y = element_blank(),则该命令将不起作用,因为theme_classic()axis.line应用于该命令,从而再次出现了两行。这就是为什么您必须在此处指定两者的原因。

相关问题