我怎样用ggplot来强调x轴呢?

  • 本文关键字:轴呢 ggplot ggplot2 axis
  • 更新时间 :
  • 英文 :


如果我使用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))

最新更新