There's more...

We can add numeric data of many different types into data tracks with karyoploteR. The following example shows how to draw some numeric data onto a plot as a simple line. The first step is to prepare our data. Here, we create a data.frame that has 100 random numbers that map into 100 windows of chromosome 4 and, as before, we create a GRanges object. This time, we'll have a data track above and below our chromosome—one for SNP markers and the other for the new data (note that this is plot.type = 2). We then need to set the parameters for the plo—in particular, the margins, to stop labels and data overlapping; but after that, it's the same plot calls, this time adding a kpLines() call. The key parameter here is y, which describes the y value of the data at each plotting point (note that this comes as a single column from our numeric_data object). We now have a plot with a numeric data track along chromosome 4. The following are the steps to be performed for this example:

  1.  Create some numeric data:
numeric_data <- data.frame(
y = rnorm(100,mean = 1,sd = 0.5 ),
chr = rep("chr4", 100),
start = seq(1,20862711, 20862711/100),
end = seq(1,20862711, 20862711/100)
)
numeric_data_gr <- makeGRangesFromDataFrame(numeric_data)
  1. Set up plot margins:
plot.params <- getDefaultPlotParams(plot.type=2)
plot.params$data1outmargin <- 800
plot.params$data2outmargin <- 800
plot.params$topmargin <- 800
  1. Create a plot and add tracks:
kp <- plotKaryotype(genome=genome_gr, plot.type = 2, plot.params = plot.params)
kpPlotMarkers(kp, snps_gr, labels = snp_labels)
kpLines(kp, numeric_data_gr, y = numeric_data$y, data.panel=2)

This results in the following output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.45.127