           .x((d) -> xScale[1][j](d))
           .y((d,i) -> yScale[1](data.lod[j].lod[i]))
 
-  randomChr = data.chr[Math.floor(Math.random()*data.chr.length)]
+  randomDraw = (x) -> x[Math.floor(Math.random()*x.length)]
+
+  randomChr = randomDraw(data.chr)
+  randomMarker = randomDraw(data.markers[randomChr])
+
+  # initial phenotype vs genotype plot
+  initialPXG = (chr, marker) ->
+    botsvg.selectAll("empty")
+          .data(data.phevals)
+          .enter()
+          .append("circle")
+          .attr("class", "plotPXG")
+          .attr("cx", (d,i) ->
+              g = Math.abs(data.geno[marker][i])
+              sx = data.sex[i]
+              if(chr=="X")
+                return xScale[3](sx*2+g-1)+jitter[i]
+              xScale[3](sx*3+g-1)+jitter[i])
+          .attr("cy", (d) -> yScale[3](d))
+          .attr("r", "3")
+          .attr("fill", (d,i) ->
+              g = data.geno[marker][i]
+              return pink if g < 0
+              darkGray)
+           .attr("stroke", (d,i) ->
+               g = data.geno[marker][i]
+               return purple if g < 0
+               "black")
+          .attr("stroke-width", (d,i) ->
+               g = data.geno[marker][i]
+               return "2" if g < 0
+               "1")
+
+  # function to revise phenotype vs genotype plot
+  revPXG = (chr, marker) ->
+    botsvg.selectAll(".plotPXG")
+           .transition().duration(1000)
+           .attr("cx", (d,i) ->
+               g = Math.abs(data.geno[marker][i])
+               sx = data.sex[i]
+               if(chr=="X")
+                 return xScale[3](sx*2+g-1)+jitter[i]
+               xScale[3](sx*3+g-1)+jitter[i])
+           .attr("fill", (d,i) ->
+               g = data.geno[marker][i]
+               return pink if g < 0
+               darkGray)
+           .attr("stroke", (d,i) ->
+               g = data.geno[marker][i]
+               return purple if g < 0
+               "black")
+           .attr("stroke-width", (d,i) ->
+               g = data.geno[marker][i]
+               return "2" if g < 0
+               "1")
 
   botsvg.append("g").append("path")
        .attr("d", botlodcurve(randomChr)(data.lod[randomChr].pos))

         .attr("stroke", "black")
         .attr("stroke-width", "2")

  # background rectangles for each chromosome, alternate color
  chrRect = topsvg.append("g").selectAll("empty")
     .data(data.chr)

  for i in [0..3]
    top[i] = pad.top
    bottom[i] = pad.top + hInner[i]

  # jitter amounts for PXG plot
  jitterAmount = (right[3] - left[3])/50
  jitter = []
  for i of data.phevals
    jitter[i] = (2.0*Math.random()-1.0) * jitterAmount

  # colors definitions
  lightGray = d3.rgb(230, 230, 230)
