【问题标题】:R: Adjusting Labels in circlize diagramR:调整圆形图中的标签
【发布时间】:2015-09-06 14:07:56
【问题描述】:

我有下面的代码,我试图使用惊人的包 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()

我看到可以基于page 17 of the vignette使用代码

# 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)

我看到Rotate labels in a chordDiagram (R circlize)的答案很相似

但是,这不会删除现有标签,例如刻度线和扇区名称。

【问题讨论】:

    标签: r chord-diagram circlize


    【解决方案1】:

    我想知道是否有一种快速的方法可以删除我的所有标签 图表包括刻度线,只需添加回 AUDI、VOLVO 和 BMW 根据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)
    

    给你

    【讨论】:

    【解决方案2】:

    我实际上遇到了同样的问题,即当我想要旋转标签时,“旧”标签仍然存在。对我来说,诀窍是使用

    chordDiagram(as.matrix(data).....等等。

    所以当我明确说我有一个矩阵时它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多