ggplot2,使用主题后轴未显示(axis.line = element_line())

M.Z*_*hao 25 axis r ggplot2

我试图使用ggplot2包绘制下面的图形,但不知何故轴不会显示.蜱虫在那里,而不是轴线.我已经使用过该theme(axis.line=element_line())功能,但它不起作用.

这是我的代码:

library(ggplot2)

ggplot(data = soepl_randsub, aes(x = year, y =satisf_org, group = id)) +
    geom_point() + geom_line() +ylab("Current Life Satisfaction") +theme_bw() +
    theme(plot.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank() ) +
    theme(panel.border= element_blank()) +
    theme(axis.line = element_line(color="black", size = "2")) 
Run Code Online (Sandbox Code Playgroud)

我不确定出了什么问题.这是图表.

在此输入图像描述

San*_*att 54

该错误已在ggplot2 v2.2.0中修复. 不再需要单独指定轴线.

我认为这是ggplot2 v2.1.0中的一个错误.(参见此错误报告这一个.)一种解决方法是分别设置在x轴和y轴线.

  library(ggplot2)

  ggplot(data = mpg, aes(x = hwy, y = displ)) + 
  geom_point() + 
  theme_bw() + 
  theme(plot.background = element_blank(),
         panel.grid.major = element_blank(),
         panel.grid.minor = element_blank() )+
  theme(panel.border= element_blank())+
  theme(axis.line.x = element_line(color="black", size = 2),
        axis.line.y = element_line(color="black", size = 2))
Run Code Online (Sandbox Code Playgroud)