How to use ggcyto_arrange to plotframes in a frameset in a new order
1
0
Entering edit mode
alavy ▴ 30
@alavy-23451
Last seen 4.6 years ago

Hi, I am trying to plot a frame set using ggycto and autoplot but also to rearrange the frames in a specific order.

I first created a vector with the sample names and then created a matrix that will show the order of the frames in the plot. I use a vector becuase I need to for another loop I have in my script, and I truncate it to 49 for another reason unrelated to this question.

# Create a 96 well plate name spece in a vector
wholeplate <- vector()
rowsinplate <- c("A","B","C","D","E","F","G","H")
for (i in rowsinplate){
  for (j in 1:12){
    wholeplate <- c(wholeplate,paste(i, j, sep=""))
  }
}

ndataset <- vector()
ndataset <- wholeplate[0:49]
#for a later use, make a matrix with 12 columns to store all sample names
layoutmtrx <- matrix(ndataset,ncol = 6, byrow=TRUE)
layoutmtrx

Plotting the frameset with autoplot works fine:
autoplot(fs, "RED.B.HLin", "FSC.HLin", bins=132) + 
  ggcyto_par_set(limits = "data")

But the frames are ordered as they were files names (A1, A10, A11, A12, A2 ...) So I try using ggcyto_arrange either with the matrix order or just changing the number of rows, but I get the same error:

ggcyto_arrange(autoplot(gs[[1]], "RED.B.HLin", "FSC.HLin", bins=132),layout_matrix = layoutmtrx)
ggcyto_arrange(autoplot(fs, "RED.B.HLin", "FSC.HLin", bins=132), nrow=2)

Error in as.ggplot(p) : object 'name' not found

Should I use another function to re-arrange the plots?

ggcyto ggcyto_arrange autoplot • 1.2k views
ADD COMMENT
0
Entering edit mode

EDIT: while the frames are read in the right order, they are still plotted in the wrong order....


I didn't mange to solve it using ggcyto_arrange, but I found an alternative solution (EDIT: actually it doesn't work, the plots are in the wrong order):

When loading all frames into the frameset I am now using mixedsort from gtools to rearrange the list of frames prior to reading it into one flowset.

ADD REPLY
0
Entering edit mode
Jake Wagner ▴ 310
@jake-wagner-19995
Last seen 4.1 years ago

autoplot was meant for the most common quick-view plotting operations, for the most part handling the layout for you. To do what you're trying to do (plots by plate well location), you should probably be working through the more flexible ggcyto method. So something like this:

# Using cytoset
cs <- load_cytoset_from_fcs(fcs_path)
rows <- toupper(letters)[1:8]
cols <- 1:12
wholeplate <- cbind(row=rep(rows, each = 12), column=rep(cols, 8))
pd <- pData(cs)
pData(cs) <- cbind(pd, wholeplate)
ggcyto(cs, aes("B710-A", "R660-A")) +
  geom_hex(bins=132) +
  facet_grid(row ~ column)

or, if you're using ncdfFlow because you're still using Bioconductor 3.10:

# Using ncdfFlowSet
fs <- read.ncdfFlowSet(list.files(fcs_path, pattern = "CytoTrol", full.names = TRUE))
rows <- toupper(letters)[1:8]
cols <- 1:12
wholeplate <- cbind(row=rep(rows, each = 12), column=rep(cols, 8))
pd <- pData(fs)
pData(fs) <- cbind(pd, wholeplate)
ggcyto(fs, aes("B710-A", "R660-A")) +
  geom_hex(bins=132) +
  facet_grid(row ~ column)

Of course, you could use a subset of the 96 (in your case, 49) and there's nothing saying you have to lay out the rows and columns as I did there, but hopefully that illustrates the idea. Just use facet_grid (like you would with ggplot). You can use any column available in the pData attached to the cytoset/flowSet/ncdfFlowSet/GatingSet for faceting.

ADD COMMENT
0
Entering edit mode

Following your code the columns (numerical) are still ordered as alphanumerical (e.g. 1, 10, 11,12, 2, 3...) and not according to the value of integers.

I tried changing the column values to be ordered factors but it didn't change the result.

Do you have a suggestions how I might solve it ?

Thanks again Jake! I really appreciate all the help!

ADD REPLY
0
Entering edit mode

Sorry for the delay. For building the wholeplate labels, I should have used a data.frame because of the heterogeneous data types. By making it a matrix it had to coerce the integers to character. Try this instead for that line:

wholeplate <- data.frame(row=rep(rows, each = 12), column=rep(cols, 8))
ADD REPLY

Login before adding your answer.

Traffic: 522 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6