简体   繁体   中英

Change x-axis label distance in qplot

I have a qplot and when I graph it, it splits up the x-axis automatically. I want to change that to split it up by defined sequential breaks, so I tried this:

breaks <- seq(a,b,7)
qplot(data=data, x=xvar, y=yvar, colour=yvar, group=grouping, 
        geom=c("point", "line")) + 
  scale_x_discrete(breaks = breaks, labels=paste("Break", breaks))

However, this didnt work. In fact, nothing shows up on the x-axis when I do that.

Sample:

  xvar yvar grouping
1   1  25        1
2   2  30        1
3   3  28        1
4   4  27        1
5   5  40        1
...
70  70 20        1

breaks <- seq(1,70,7)

Since your x variable data is continuous, you need to use scale_x_continuous . You may also want to rotate the x labels by 90 degrees:

qplot(data=data, x=xvar, y=yvar, colour=yvar, group=grouping, 
        geom=c("point", "line")) + 
    scale_x_continuous(breaks = breaks, labels=paste("Break", breaks)) +
    opts(axis.text.x = theme_text(angle=90))

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM