2015-09-06 115 views
0

我有下面这些代码进出口试图使成圆形图使用R:在circlize图调整标签

我已阅读vigenette,承认它的一些已经在我头上有点惊人的包circlize ,

我想知道是否有一个快速的方法来删除我的图表上的所有标签,包括刻度标记,并且只需按照与这个扇区相同的角度在浅灰色中添加回奥迪,沃尔沃和宝马example

library (dplyr) 
library(circlize) 

df = read.table(textConnection(" 
Brand_from model_from Brand_to Model_to 
          VOLVO  s80  BMW 5series 
          BMW 3series  BMW 3series 
          VOLVO  s60 VOLVO  s60 
          VOLVO  s60 VOLVO  s80 
          BMW 3series  AUDI  s4 
          AUDI   a4  BMW 3series 
          AUDI   a5  AUDI  a5 
          "), header = TRUE, stringsAsFactors = FALSE) 


# Add customer satisfaction (1 being positive, 0 being negative) 
df <- df %>% 
    mutate(Customer.Sat = c("POS","NEG","NEG","POS","POS","NEG","NEG")) %>% 
    select(Brand_from,Brand_to,Customer.Sat) 

# Set the colour Scheme for the association 
col = c("NEG" = "red", 
    "POS" = "green") 

diffHeight = c("POS" = -0.02, 
      "NEG" = 0.04) 

# Build the Chord Diagram 
chordDiagram(df[1:2], 
     col = col[df$Customer.Sat], 
     diffHeight = diffHeight[df$Customer.Sat]) 

circos.clear() 

我看到有可能使用我所见过的答案Rotate labels in a chordDiagram (R circlize)这是非常相似

然而,这并不删除现有的标签,如刻度线和部门的名称代码

# Rotates the Labels so they are 90 Degrees to the chord diagram 
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) { 
xlim = get.cell.meta.data("xlim") 
ylim = get.cell.meta.data("ylim") 
sector.name = get.cell.meta.data("sector.index") 
circos.text(mean(xlim), ylim[1] + .1, sector.name, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5)) 
circos.axis(h = "top", labels.cex = 0.5, major.tick.percentage = 0.2,  sector.index = sector.name, track.index = 2) 
}, bg.border = NA) 

基于page 17 of the vignette

回答

2

我在想,如果有一个快速的方法,以消除我的 图,包括刻度标记,只是浅灰色以相同的角度加回奥迪,沃尔沃和宝马 该部门的所有标签为每this example

你可以尝试

chordDiagram(df[1:2], col = col[df$Customer.Sat], diffHeight = diffHeight[df$Customer.Sat], annotationTrack = "grid", preAllocateTracks = 1) 
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) { 
    xlim = get.cell.meta.data("xlim") 
    ylim = get.cell.meta.data("ylim") 
    sector.name = get.cell.meta.data("sector.index") 
    circos.text(mean(xlim), ylim[1] + .1, sector.name, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5), col = "lightgray") 
}, bg.border = NA) 

,让你

enter image description here

+0

嗨lukeA谢谢你,你能解释一下代码吗,这样我就可以在将来更容易地拍出更复杂的例子.....感谢你的时间 –

+0

你会在小插曲中找到一个解释:https: //cran.r-project.org/web/packages/circlize/vignettes/visualize_relations_by_chord_diagram.pdf#page=16 – lukeA