GGPLOT2: Distance of discrete values of from each end of x-axis

后端 未结 2 725
终归单人心
终归单人心 2020-12-21 18:33

I have been working with the code below. Everything seems to work okay, except that the discrete values on the x-axis are far from each end of the graph. I\'ve tried several

2条回答
  •  醉梦人生
    2020-12-21 18:47

    With a factor you can add:

    scale_x_discrete(expand=c(0, 0))
    

    to plot all the way to the edges:

    df <- data.frame(x=factor(letters[1:10]), y=rnorm(100), group=rep(letters[20:24], each=20))
    
    p <- ggplot(df, aes(x=x, y=y, colour=group)) + geom_line()
    c <- scale_x_discrete(expand=c(0, 0)
    
    p
    p + c
    

    but I'm not sure exactly what you're trying for without some sample data.

提交回复
热议问题