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

孤人 提交于 2019-11-29 16:33:33

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.

Try it again, but convert vicryl.long$pre_post to a continuous numeric variable rather than a factor and it will plot to the edges, rather than center (as it should) as a categorical variable.

vicryl.long$pre_post <- as.numeric(as.character(vicryl.long$pre_post))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!