首页 > 解决方案 > ggplot绘图区域顶部和底部的线条

问题描述

我想在使用 ggplot2 创建的图的顶部和底部添加一条线(x 标签和轴下方的底线)。到目前为止,我已经在绘图周围添加了一个矩形,但我不希望两边有线条。

x <- 1:10
y <- rnorm(10,mean = x)
df <- data.frame(x,y)
library(ggplot2)
ggplot(data = df, mapping = aes(x,y)) + geom_point() +
  theme(plot.background = element_rect(size = 1, color = 'blue'))

我希望你们有一个解决方案。

标签: rggplot2themes

解决方案


类似的东西会起作用吗?

x <- 1:10
y <- rnorm(10,mean = x)
df <- data.frame(x,y)
ggplot(data = df, mapping = aes(x,y)) + geom_point() +
    annotate(geom = 'segment', 
             y = Inf, 
             yend = Inf, 
             x = -Inf, 
             xend = Inf, 
             size = 2) +
    theme(axis.line.x = element_line(size = 1))

在此处输入图像描述


推荐阅读