R 如何使用 ggplot 强调 x 轴?

R How can I emphasize the x axis using ggplot?

如果我使用 ggplot,则 x 轴 (y==0) 的水平线与 y 的任何其他值相同。我想强调一个事实,即图表的底部不是 x 轴,并且 x 轴在图中更高。我该怎么做?

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5)

您可以用黑线突出显示轴

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) +
geom_point(size = 5) +
geom_hline(aes(yintercept = 0)) +
geom_vline(aes(xintercept = 0))

您还可以通过添加例如直接更改坐标轴的颜色和宽度:

+ theme(axis.line = element_line(colour = 'red', size = 2))