Body: <p>This is the <a href="https://stackoverflow.com/questions/42917349/r-circlize-circos-plot-how-to-plot-unconnected-areas-between-sectors-with-min/42996677">post</a> where they made circos using R I'm just following that the part answered by Zuguang Gu, not not sure what I'm doing wrong my <a href="https://drive.google.com/open?id=1UNkUO6numTeoLiBZlcl4kc7ah-roELWN" rel="nofollow noreferrer">file</a>, and the code:</p>
  
  <pre><code>library(ComplexHeatmap)
  library(circlize)
   d11 &lt;- read.csv("DC3_7_MUT.txt",stringsAsFactors = FALSE)
  a &lt;- as.data.frame(d11)
  head(a)
  
  
  ex &lt;- melt(a, id.vars=c("Gene"))
  head(ex)
  dim(ex)
  
  bb1 &lt;- ex %&gt;% na.omit() %&gt;%
    group_by(Gene,value) %&gt;% 
    mutate(new = n()) %&gt;% 
    data.frame()
  
  #head(bbb)
  #dim(bbb)
  
  bb1[bb1==""]&lt;-NA
  
  df &lt;- na.omit(bb1)
  
  bbb &lt;- df
  
  features1 = unique(bbb[[3]])
  features_col1 = structure(rand_color(length(features1)), names = features1)
  
  patients_col1 = structure(1:187, names = unique(bbb[[2]])) # I don't understand this
  
  
  
  col1 = ifelse(bbb[[4]], features_col1[bbb[[3]]], "#FFFFFF00")
  col1 = gsub("FF$", "80", col1) # half transparent
  features_count1 = tapply(bbb[[4]], bbb[[3]], sum)
  head(bbb)
  # set color to white if it only exists in one patient/cell
  col1[features_count1[bbb[[3]]] == 1] = "#FFFFFF00"
  pdf("CIRCOS.pdf",20,25)
  chordDiagram(bbb, col = col1, grid.col = c(features_col1, patients_col1))
  
  
  dev.off()
  </code></pre>
  
  <p>The error </p>
  
  <blockquote>
    <p>chordDiagram(bbb, col = col1, grid.col = c(features_col1,
    patients_col1)) Error in abs(df$value1[i]) :    non-numeric argument
    to mathematical function</p>
  </blockquote>
  
  <p>I'm doing something wrong but I'm not able to find out, secondly I didn't get the idea about the usage of structure the one I commented.</p>
  
  <p>Am I using the right dimension for the structure argument?</p>
  
  <p>A bit of progress with a bit of tweak in the code </p>
  
  <pre><code>d11 &lt;- read.csv("DC3_7_MUT.txt",stringsAsFactors = FALSE)
  
  
  blank2na &lt;- function(x){ 
    z &lt;- gsub("\\s+", "", x)  #make sure it's "" and not " " etc
    x[z==""] &lt;- NA 
    return(x)
  }
  
  a1 &lt;- data.frame(sapply(d11,  blank2na))
  
  df &lt;- a1
  head(df)
  
  df2 &lt;- df[, colSums(is.na(df)) != nrow(df)]
  
  head(df2)
  dim(df2)
  
  
  
  a &lt;- as.data.frame(df2)
  head(a)
  ex &lt;- melt(a, id.vars=c("Gene"))
  head(ex)
  dim(ex)
  ex &lt;- with(ex, table(paste(Gene,variable,sep='|'), value))
  ex = as.data.frame(ex, stringsAsFactors = FALSE)
  head(ex)
  ex &lt;- ex[which(ex<span class="math-container">$value != ""),]
  head(ex)
  dim(ex)
  ex &lt;- (ex[which(ex$</span>Freq == 1),])
  head(ex)
  dim(ex)
  
  
  features = unique(ex[[2]])
  features_col = structure(rand_color(length(features)), names = features)
  patients_col = structure(1:280, names = unique(ex[[2]]))
  col = ifelse(ex[[3]], features_col[ex[[2]]], "#FFFFFF00")
  col = gsub("FF$", "80", col) # half transparent
  features_count = tapply(ex[[3]], ex[[2]], sum)
  # set color to white if it only exists in one patient/cell
  col[features_count[ex[[2]]] == 1] = "red" 
  
  #And the final chord diagram:
  
  pdf("CIRCOS.pdf",20,25)
  
  #png("circos.png",width =20,height=20,unit="cm",res=1000)
  #chordDiagram(ex, col = col, grid.col = c(features_col, patients_col))
  
  chordDiagram(ex, col = col, grid.col = patients_col, directional = 1,
               transparency = 0.25 , xmax = NULL,
               symmetric = FALSE, keep.diagonal = FALSE,
               direction.type = "diffHeight", diffHeight = convert_height(2, "mm"),
               reduce = 1e-5, self.link = 2,big.gap = 10,
               preAllocateTracks = NULL,
               annotationTrack = c("name", "grid", "axis"),
               annotationTrackHeight = convert_height(c(3, 2), "mm"),
               link.border = NA, link.lwd = par("lwd"), link.lty = par("lty"),
               link.sort = FALSE, link.decreasing = TRUE,scale = TRUE,
               link.arr.lwd = par("lwd"), link.arr.col = par("col"),
               link.largest.ontop = FALSE, link.visible = TRUE)
  
  
  dev.off()
  </code></pre>
  
  <p><a href="https://i.sstatic.net/fUU8m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fUU8m.png" alt="this is somewhat im trying to but still not understandable "></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-28T23:11:10.410Z
Comments.Text: What exactly are you trying to achieve? What does each connection in the circos plot represent?
Comments.UserDisplayName: h3ab74
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-02T06:30:00.877Z
Comments.Text: this i finally discarded ...
Comments.UserDisplayName: kcm
Tags: <r><circos>
Title: Circos plot with circlize
ThreadText: # Circos plot with circlize
  
  (Asked by: username_0 on 2019-01-17)
  
  This is the [post](https://stackoverflow.com/questions/42917349/r-circlize-circos-plot-how-to-plot-unconnected-areas-between-sectors-with-min/42996677) where they made circos using R I'm just following that the part answered by Zuguang Gu, not not sure what I'm doing wrong my [file](https://drive.google.com/open?id=1UNkUO6numTeoLiBZlcl4kc7ah-roELWN), and the code:
  
  ```
  library(ComplexHeatmap)
  library(circlize)
   d11 <- read.csv("DC3_7_MUT.txt",stringsAsFactors = FALSE)
  a <- as.data.frame(d11)
  head(a)
  
  ex <- melt(a, id.vars=c("Gene"))
  head(ex)
  dim(ex)
  
  bb1 <- ex %>% na.omit() %>%
    group_by(Gene,value) %>% 
    mutate(new = n()) %>% 
    data.frame()
  
  #head(bbb)
  #dim(bbb)
  
  bb1[bb1==""]<-NA
  
  df <- na.omit(bb1)
  
  bbb <- df
  
  features1 = unique(bbb[[3]])
  features_col1 = structure(rand_color(length(features1)), names = features1)
  
  patients_col1 = structure(1:187, names = unique(bbb[[2]])) # I don't understand this
  
  col1 = ifelse(bbb[[4]], features_col1[bbb[[3]]], "#FFFFFF00")
  col1 = gsub("FF$", "80", col1) # half transparent
  features_count1 = tapply(bbb[[4]], bbb[[3]], sum)
  head(bbb)
  # set color to white if it only exists in one patient/cell
  col1[features_count1[bbb[[3]]] == 1] = "#FFFFFF00"
  pdf("CIRCOS.pdf",20,25)
  chordDiagram(bbb, col = col1, grid.col = c(features_col1, patients_col1))
  
  dev.off()
  
  ```
  
  The error
  
  > chordDiagram(bbb, col = col1, grid.col = c(features\_col1,
  > patients\_col1)) Error in abs(df$value1[i]) : non-numeric argument
  > to mathematical function
  
  I'm doing something wrong but I'm not able to find out, secondly I didn't get the idea about the usage of structure the one I commented.
  
  Am I using the right dimension for the structure argument?
  
  A bit of progress with a bit of tweak in the code
  
  ```
  d11 <- read.csv("DC3_7_MUT.txt",stringsAsFactors = FALSE)
  
  blank2na <- function(x){ 
    z <- gsub("\\s+", "", x)  #make sure it's "" and not " " etc
    x[z==""] <- NA 
    return(x)
  }
  
  a1 <- data.frame(sapply(d11,  blank2na))
  
  df <- a1
  head(df)
  
  df2 <- df[, colSums(is.na(df)) != nrow(df)]
  
  head(df2)
  dim(df2)
  
  a <- as.data.frame(df2)
  head(a)
  ex <- melt(a, id.vars=c("Gene"))
  head(ex)
  dim(ex)
  ex <- with(ex, table(paste(Gene,variable,sep='|'), value))
  ex = as.data.frame(ex, stringsAsFactors = FALSE)
  head(ex)
  ex <- ex[which(ex$value != ""),]
  head(ex)
  dim(ex)
  ex <- (ex[which(ex$Freq == 1),])
  head(ex)
  dim(ex)
  
  features = unique(ex[[2]])
  features_col = structure(rand_color(length(features)), names = features)
  patients_col = structure(1:280, names = unique(ex[[2]]))
  col = ifelse(ex[[3]], features_col[ex[[2]]], "#FFFFFF00")
  col = gsub("FF$", "80", col) # half transparent
  features_count = tapply(ex[[3]], ex[[2]], sum)
  # set color to white if it only exists in one patient/cell
  col[features_count[ex[[2]]] == 1] = "red" 
  
  #And the final chord diagram:
  
  pdf("CIRCOS.pdf",20,25)
  
  #png("circos.png",width =20,height=20,unit="cm",res=1000)
  #chordDiagram(ex, col = col, grid.col = c(features_col, patients_col))
  
  chordDiagram(ex, col = col, grid.col = patients_col, directional = 1,
               transparency = 0.25 , xmax = NULL,
               symmetric = FALSE, keep.diagonal = FALSE,
               direction.type = "diffHeight", diffHeight = convert_height(2, "mm"),
               reduce = 1e-5, self.link = 2,big.gap = 10,
               preAllocateTracks = NULL,
               annotationTrack = c("name", "grid", "axis"),
               annotationTrackHeight = convert_height(c(3, 2), "mm"),
               link.border = NA, link.lwd = par("lwd"), link.lty = par("lty"),
               link.sort = FALSE, link.decreasing = TRUE,scale = TRUE,
               link.arr.lwd = par("lwd"), link.arr.col = par("col"),
               link.largest.ontop = FALSE, link.visible = TRUE)
  
  dev.off()
  
  ```
  
  [![this is somewhat im trying to but still not understandable ](https://i.sstatic.net/fUU8m.png)](https://i.sstatic.net/fUU8m.png)
  
  **Tags:** r, circos
  
  > **Comments:**
  > **username_1**: What exactly are you trying to achieve? What does each connection in the circos plot represent?  
  > **username_0**: this i finally discarded ...  
  
  ---
  
  ## 0 answers
  
  