简体   繁体   中英

Increase distance between axis line and plot lines on ggplot

How do I increase the distance between the axis.line.y below and the blue geom_hline below? I want a gap between the two, I don't want them kissing as shown on the plot.

library(tidyverse)
ggplot(mpg, aes(cty, hwy)) + 
  geom_point() + 
  geom_hline(yintercept = 25, color = "blue") + 
  theme_minimal() + 
  theme(axis.line.y = element_line(color = "black"), 
        axis.ticks.y.left = element_line(color = "black"), 
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank())

在此输入图像描述

I'm not sure if this is exactly what you want but try it.

library(tidyverse)
ggplot(mpg, aes(cty, hwy)) + 
  geom_point() + 
  geom_segment(aes(x = min(cty), y = 25, 
                   xend = max(cty), yend = 25), 
               data = mpg) +
  theme_minimal() + 
  theme(axis.line.y = element_line(color = "black"), 
        axis.ticks.y.left = element_line(color = "black"), 
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank())

[1]:https://i.stack.imgur.com/q112f.png

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