ggplot2,使用主题后轴不显示(axis.line=element_line()) [英] ggplot2, axis not showing after using theme(axis.line=element_line())

查看:27
本文介绍了ggplot2,使用主题后轴不显示(axis.line=element_line())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ggplot2 包绘制以下图形,但不知何故轴不会显示.刻度在那里,只是不是轴线.我使用了 theme(axis.line=element_line()) 函数,但它不起作用.

I am trying to draw this following graph using ggplot2 package, but somehow the axis won't show up. the ticks are there, just not the axis line. I have used the theme(axis.line=element_line()) function, but it wouldn't work.

这是我的代码:

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")) 

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

I am not sure what went wrong. Here is the chart.

推荐答案

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

The bug was fixed in ggplot2 v2.2.0 There is no longer a need to specify axis lines separately.

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

I think this is a bug in ggplot2 v2.1.0. (See this bug report and this one.) A workaround is to set the x-axis and y-axis lines separately.

  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))

这篇关于ggplot2,使用主题后轴不显示(axis.line=element_line())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆