0
votes

Here I've got a data-frame consisted of 3264 normalized datapoint for 34 samples (3264 x 34). I have generated a ggplot using the following script:

cl21  <- geom_line(aes(y=CL021, col="CL"))
cl22  <- geom_line(aes(y=CL022, col="CL"))
cl24  <- geom_line(aes(y=CL024, col="CL"))
cl25  <- geom_line(aes(y=CL025, col="CL"))
cl27  <- geom_line(aes(y=CL027, col="CL"))
cl28  <- geom_line(aes(y=CL028, col="CL"))
cl30  <- geom_line(aes(y=CL030, col="CL"))
cl33  <- geom_line(aes(y=CL033, col="CL"))
cl35  <- geom_line(aes(y=CL035, col="CL"))
cl36  <- geom_line(aes(y=CL036, col="CL"))
cl37  <- geom_line(aes(y=CL037, col="CL"))
cl38  <- geom_line(aes(y=CL038, col="CL"))
cl39  <- geom_line(aes(y=CL039, col="CL"))
cl40  <- geom_line(aes(y=CL040, col="CL"))
ng172  <- geom_line(aes(y=NG172, col="NG"))
ng176  <- geom_line(aes(y=NG176, col="NG"))
ng178  <- geom_line(aes(y=NG178, col="NG"))
ng190  <- geom_line(aes(y=NG190, col="NG"))
ng191  <- geom_line(aes(y=NG191, col="NG"))
ng195  <- geom_line(aes(y=NG195, col="NG"))
ng218  <- geom_line(aes(y=NG218, col="NG"))
ng232  <- geom_line(aes(y=NG232, col="NG"))
ng244  <- geom_line(aes(y=NG244, col="NG"))
ng264  <- geom_line(aes(y=NG264, col="NG"))
ng285  <- geom_line(aes(y=NG285, col="NG"))
ng289  <- geom_line(aes(y=NG289, col="NG"))
ng299  <- geom_line(aes(y=NG299, col="NG"))
ng302  <- geom_line(aes(y=NG302, col="NG"))
ng306  <- geom_line(aes(y=NG306, col="NG"))
ng318  <- geom_line(aes(y=NG318, col="NG"))
ng320  <- geom_line(aes(y=NG320, col="NG"))
ng335  <- geom_line(aes(y=NG335, col="NG"))
ng338  <- geom_line(aes(y=NG338, col="NG"))
ng367  <- geom_line(aes(y=NG367, col="NG"))
gplot(normDF, aes(x=pos, y= value))+ cl21 +cl22  +cl24 +cl25 +cl27 +cl28 +cl30 +cl33 +cl35 +cl36 +cl37 +cl38 +cl39 +cl40 + ng172+ ng176+ ng178+ ng190+ ng191+ ng195+ ng218+ ng232+ ng244+ ng264+ ng285+ ng289+ ng299+ ng302+ ng306+ ng318+ ng320+ ng335+ ng338+ ng367  -> p

I tried to add customized tick marks along the x axis by defining breaks and labels:

p + xlab("FGD1 exons")+ ylab('Normalized Depth')+ scale_alpha_discrete(breaks= c("327","492","675","822","945","997","1098","1212","1380","1460","1620","1798","1968","2079","2542","2741","2936","3263"), labels= c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18"))+ theme(axis.text.x  = element_text(angle=90,vjust=0.5, size=15,hjust=1))

but ticks are not appearing on my plot! I was wondering if anyone here can advice me on this!

1
why are you using scale_alpha_discrete to control the x axis?bouncyball
without normDF it is really hard to help you. Also, this example is probably not the simplest example you could come up with that reproduces your issue. Also, that is probably not the the easiest way to add a bunch of different lines to a plot (see the group argument)Chris
I also tried scale-x_discrete, no good!RJF

1 Answers

2
votes

I think you need to be using scale_x_continuous since your values are continuous.

Here is an example, including an MWE, showing how to do speed up your process a bit using melt from the reshape2 package to simplify things:

library(reshape2)
library(ggplot2)

df <-
  data.frame(
    x = 1:100
    , ya = 1:100
    , yb = seq(1,50, length.out = 100)
    , yc = seq(1,25, length.out = 100)
    , yd = seq(1,10, length.out = 100)
  )

melted <- 
  melt(df, id.vars ="x")

melted$set <-
  ifelse(melted$variable %in% c("ya","yb")
         , "set A"
         , "set B")

head(melted)

ggplot(melted
       , aes(x, value
             , group = variable
             , col = set)) +
  geom_line() +
  scale_x_continuous(breaks = c(1, 20, 55, 80)
                     , labels = c(1,2,3,4))

enter image description here

I had missed that the column names contain the color information in your original set, you can do even automate the colors using substr:

df <-
  data.frame(
    x = 1:100
    , CLa = 1:100
    , CLb = seq(1,50, length.out = 100)
    , NGc = seq(1,25, length.out = 100)
    , NGd = seq(1,10, length.out = 100)
  )

melted <- 
  melt(df, id.vars ="x")

melted$set <-
  substr(melted$variable, 1, 2)

head(melted)

ggplot(melted
       , aes(x, value
             , group = variable
             , col = set)) +
  geom_line() +
  scale_x_continuous(breaks = c(1, 20, 55, 80)
                     , labels = c(1,2,3,4))