简体   繁体   中英

How to enable x-axis and y-axis line in GGPLOT theme_classic()

With this code:

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

I expect to get image like this:

在此处输入图片说明

But how come I get this instead:

在此处输入图片说明

Notice the missing x-axis an y-axis line. How can I enable it?

This is theme_classic() specific issue.

Here is a solution from this 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'))

Edit

If you are running into this issue, updating ggplot2 should fix the issue, and the solution above shouldn't be necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM