R语言 如何在ggplot上使x轴和y轴的起点相同?

mepcadol  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(209)

假设我有这个df,我用ggplot创建了一个图

  1. df = data.frame(x = 1:10,
  2. y = -10,1)
  3. df
  4. library(ggplot2)
  5. ggplot(df)+aes(x=x,y=y)+
  6. theme_classic()+
  7. scale_x_continuous(breaks = 0:10,limits=c(0,10))+
  8. scale_y_continuous(breaks = -10:0,limits=c(-10,0) )

我希望标签0(x轴)和-10(y轴)位于x轴和y轴的交点上

krcsximq

krcsximq1#

我通常做的是将expand = c(0,0)添加到scale_x/y_continuous-它将是:

  1. ggplot(df) + aes(x = x, y = y)+
  2. theme_classic() +
  3. scale_x_continuous(expand = c(0,0), breaks = 0:10, limits=c(0,10)) +
  4. scale_y_continuous(expand = c(0,0), breaks = -10:0, limits=c(-10,0))

相关问题