2016-07-11 78 views
1

有了這個代碼:如何啓用x軸和y軸線GGPLOT theme_classic()

library(ggplot2) 
ToothGrowth$dose <- as.factor(ToothGrowth$dose) 
p <- ggplot(ToothGrowth, aes(x=dose, y=len, color=dose, shape=dose)) + 
    geom_jitter(position=position_jitter(0.2))+ 
    labs(title="Plot of length by dose",x="Dose (mg)", y = "Length") 
p + theme_classic() 

我希望得到像這樣的:

enter image description here

但是怎麼來的我得到這個代替:

enter image description here

公告缺少的x軸和y軸線。 如何啓用它?

這是theme_classic()的具體問題。

+0

確定一個解決方案,我也一樣:'[R版本3.3.0'和'ggplot2_2.1.0' – Jimbou

+0

如果你看看theme_classic你會看到的定義axis.line.x和axis.line.y都設置爲element_blank。要麼自己改變這個定義,要麼你可以在包裝中使用theme_classic2。 –

回答

1

下面是從這個GitHub上issue

p + theme_classic() + 
    theme(axis.line.x = element_line(colour = 'black', size=0.5, linetype='solid'), 
      axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'))