0

My data as per "dput(df)" output using Rstudio in Windows7ultimate system:

> dput(df)
structure(list(time = structure(c(5L, 2L, 8L, 4L, 1L, 7L, 3L, 6L), .Label = c("G1", "G1_S", "G2", "G2_M", "G2M_G1", "M", "S", "S_G2"), class = "factor"), RB1_total = c(0.571337, -0.933077, -0.0660497, -0.1121, -0.571337, 0.36174, 0.42779, 0.53989), S.249 = c(0.270073, 0.170127, 0.0912204, 0.100353, -0.270073, -0.4402, -0.53142, -0.631773), T.252 = c(0.434422, -0.749758, -0.58248, NaN, -0.434422, 0.315335, 0.897816, NaN), T.345 = c(NaN, NaN, -0.0607041, NaN, NaN, NaN, 0.0607041, NaN), S.347 = c(NaN, NaN, 0.150658, NaN, NaN, NaN, -0.150658, NaN), T.353 = c(0.484345, NaN, 0.17213, -0.256059, -0.484345, NaN, -0.17213, 0.0839295), T.356 = c(0.489195, -0.312565, -0.0684749, NaN, -0.489195, -0.176629, -0.108154, NaN), S.807 = c(0.286962, NaN, 0.558877, NaN, -0.286962, NaN, -0.558877, NaN), S.816 = c(NaN, NaN, 0.197244, NaN, NaN, NaN, -0.197244, NaN), T.821 = c(0.32722, 0.654879, 0.318102, -0.680306, -0.32722, -0.982098, -1.3002, -0.619894), T.823 = c(0.387246, -0.375746, 0.244286, 0.489502, -0.387246, -0.0115, -0.255786, -0.745288), T.826 = c(-0.349522, 1.08947, 0.578631, 0.588223, 0.349522, -0.739952, -1.31858, -1.90681), S.855 = c(0.237007, -0.890089, NaN, NaN, -0.237007, 0.653083, NaN, NaN)), .Names = c("time", "RB1_total", "S.249", "T.252", "T.345", "S.347", "T.353", "T.356", "S.807", S.816", "T.821", "T.823", "T.826", "S.855"), class = "data.frame", row.names = c(NA, -8L))

My code, capable of displaying data for all 4 levels of factor "time" as a single row of panels per variable (it required ggplot2, reshape2, RColorBrewer, grid, and plyr packages):

dftop=df[1:4,]
dfbot=df[5:8,]

dRt=melt(dftop,id=c("time"))
dRt$time <- as.character(dRt$time)
dRt$time <- factor(dRt$time, levels=unique(dRt$time))

dRb=melt(dfbot,id=c("time"))
dRb$time <- as.character(dRb$time)
dRb$time <- factor(dRb$time, levels=unique(dRb$time))


cols<- colorRampPalette(c('black','grey','magenta','cyan','green','orange','red'))(13)

Rbot <- ggplot(dRb, aes(x=time, y=value,colour=variable, group = variable)) + 
  geom_line(size=2) +
  facet_wrap(~ variable, nrow = 1) +
  scale_colour_manual(values=c(cols)) + 
  xlab("Concatenated Sets") + 
  ylab("Log2 Normalized Relative Ratio") +
  geom_point(aes(size=value), show_guide=FALSE) +
  scale_size(guide="none") +
  geom_point(aes(fill=value,size=value-0.5),colour="black",shape=21) +
  geom_hline(yintercept=1, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=-1, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=0, color="black", size=0.5) +
  theme(legend.position="none")
Rbot

result1

The above plot is alternatively required as vertical panels, which was attempted by a simple line change:

 facet_wrap(variable ~ ., scales = "fixed",ncol = 1)

However this resulted in: Error in layout_base(data, vars, drop = drop) : At least one layer must contain all variables used for facetting. Unclear as to how to amend this efficiently and get the wanted vertical display.

Finally, for the last bit

Rtop <- ggplot(dRt, aes(x=time, y=value, width=.75, fill=variable)) + 
  geom_bar(stat="identity", position="dodge") +
  facet_wrap(~ variable, nrow = 1) +
  xlab("Paired Sets") + 
  ylab("Log2 Normalized Relative Ratio") +
  geom_hline(yintercept=0.5, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=-0.5, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=0, color="black", size=0.75) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),legend.position="none")
Rtop

result2

Output only displays default ggplot2 rainbow scale, rather than adopting the same manual colour scheme used in the geom_lines shown in result1.

RtopVal <- ggplot(dRt, aes(x=time, y=value, width=.75)) + 
  geom_bar(aes(fill=value),stat="identity", position="dodge") +
  facet_wrap(~ variable, nrow = 1) +
  scale_colour_manual(values=c(cols)) + 
  xlab("Paired Sets") + 
  ylab("Log2 Normalized Relative Ratio") +
  geom_hline(yintercept=0.5, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=-0.5, linetype="dotted", color="red", size=0.75) +
  geom_hline(yintercept=0, color="black", size=0.75) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
RtopVal

result3

It's for now the adopted alternative closest to a desirable outcome.

Thank you for your time!

  • 3
    You probably need `facet_wrap(~ variable, scales = "fixed", ncol = 1)` (notice the missing point and the place of the `~` symbol) or `facet_grid(variable ~ .)` – Jaap Nov 18 '15 at 19:58
  • 1
    The second issue of the fill of the bars may be solved by `+ scale_fill_manual(values = cols)` – Heroka Nov 18 '15 at 20:04
  • 1
    @AnaMariaMendes-Pereira you need `facet_wrap(~variable)` – Heroka Nov 18 '15 at 20:22
  • 1
    See my first comment, you also have to be aware of the position of the `~` symbol (like in `facet_wrap(~ variable)`). – Jaap Nov 18 '15 at 20:22
  • thank you `facet_grid(variable ~ .)` gets the variable labels on the right hand side of the vertical display. `facet_wrap(~ variable, ncol = 1)` or `facet_wrap(~ variable, nrow = 13)`, in my case, do not. thank you guys. Second issue also solved by @Heroka suggestion `+ scale_fill_manual(values = cols)` – Ana Maria Mendes-Pereira Nov 18 '15 at 20:40
  • One last thing, for the geom_line plot switch to vertical layout by facet_grid, how would the colour argument need to be changed to adopt the defined manual scale? at the moment i'm having a hard time to incorporate this as I'm a fairly new user of the ggplot package. cheers! – Ana Maria Mendes-Pereira Nov 19 '15 at 12:17

0 Answers0