有人能帮帮我吗?如何在数据中添加circos函数?当我尝试的时候,我得到了一个错误信息,它没有产生任何结果,我想做一个像数字1这样的圆环图,但我有一个其他的结果,我们可以在另一张图中看到。尝试跟随this guide

我的数据是这样的:
Name;Integrons_1;Integrons_2;Integrons_3;TEM;SHV;CTX_M;NDM;OXA_48
HZ1410;1;0;0;1;1;0;1;1
HZ0411;1;0;0;1;0;0;0;1
WI1410;1;0;0;1;1;0;0;1
WI0411;1;0;0;1;0;0;1;0
FR1410;1;0;0;1;0;0;0;0
FR0411;0;0;0;1;1;0;0;0
CN1410;1;0;0;1;1;0;1;0
CN0411;1;0;0;1;0;0;0;1
SA0912;0;0;0;0;0;0;0;0
SA0302;1;0;0;1;0;0;0;0
BL0912;1;0;0;1;1;0;0;0
BL0302;1;0;0;1;1;1;0;1
CSI0912;1;1;0;1;0;0;0;1
CSI0302;1;0;0;1;1;1;1;1
CSII0912;1;1;0;1;0;1;1;0
CSII0302;1;0;0;1;0;0;0;0
BGI0503;1;1;1;1;1;0;0;0
BGI0610;1;0;0;1;1;0;0;0
BGII0503;1;1;1;1;1;0;0;0
BGII0610;1;0;1;1;1;0;0;0
BCI0503;1;0;1;1;1;0;1;1
BCI0610;1;0;1;1;0;0;0;0
BCII0503;1;0;1;1;1;0;1;0
BCII0610;1;0;1;1;0;0;0;0
BDI0503;1;0;0;1;1;0;0;0
BDI0610;1;1;1;1;1;1;1;0
BDII0503;1;0;1;1;0;1;0;0
BDII0610;1;1;1;1;1;1;0;1
YPI0503;1;0;1;1;0;0;0;0
YPI0710;1;1;1;1;1;1;0;1
YPII0503;1;0;1;1;0;0;0;1
YPII0710;1;1;1;1;1;1;0;0
YMI0503;1;1;1;1;1;0;1;0
YMI0710;1;1;1;1;1;1;1;1
YMII0503;1;1;1;1;1;0;0;1
YMII0710;1;1;1;1;1;1;1;1
YSI0503;1;1;0;0;1;0;0;0
YSI0710;1;1;1;1;1;1;1;1
YSII0503;1;1;0;1;1;0;0;0
YSII0710;0;1;1;1;1;0;0;0我的代码如下所示:
#### IMPORT DES DONNEES ####
nba = read.csv("essai_r.csv", sep=";", header=T)
#attention : toujours utilise le format csv avec le sep = ";" pour avoir de
#beaux tableaux
#### INSTALLATION DES LIBRARY ####
library(reshape)
library(ggplot2)
library(plyr)
library(circlize)
#### CREATION DES TABLEAUX : FCT MELT ####
nba$Name <- with(nba, reorder(Name, GES))
nba.m <- melt(nba)
#pas utilise car ce n'est pas ce que je veux
#nba.m <- ddply(nba.m, .(variable), transform, value = scale(value))
#### MODIFICATION DES DONNEES : FACTOR -> NUMERIQUES ####
# Convert the factor levels to numeric + quanity to determine size of hole.
nba.m$var2 = as.numeric(nba.m$variable) + 15
# Labels and breaks need to be added with scale_y_discrete.
y_labels = levels(nba.m$variable)
y_breaks = seq_along(y_labels) + 15
#### CREATION DE LA HEATMAP (DEGRADE DE COULEUR UNIQUEMENT) ####
p2 = ggplot(nba.m, aes(x=Name, y=var2, fill=value)) +
geom_tile(colour="black") +
scale_fill_gradient(low = "beige", high = "red") +
ylim(c(0, max(nba.m$var2) + 0.5))
scale_y_discrete(breaks=y_breaks, labels=y_labels) +
coord_polar(theta="x") +
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
ggsave(filename="plot_2.png", plot=p2, height=7, width=7)
#sauvegarde le fichier dans le dossier
circos.par(start.degree = 90, gap.degree = 10)
#### CREATION DE LA HEATMAP BIS (AVEC NOMS DE SITES )
nba.labs <- subset(nba.m, variable==levels(nba.m$variable)[nlevels(nba.m$variable)])
nba.labs <- nba.labs[order(nba.labs$Name),]
nba.labs$ang <- seq(from=(360/nrow(nba.labs))/1.5, to=(1.5*(360/nrow(nba.labs)))-360, length.out=nrow(nba.labs))+80
nba.labs$hjust <- 0
nba.labs$hjust[which(nba.labs$ang < -90)] <- 1
p3 = ggplot(nba.m, aes(x=Name, y=var2, fill=value)) +
geom_tile(colour="black") +
geom_text(data=nba.labs, aes(x=Name, y=var2+1.5,
label=Name, angle=ang, hjust=hjust), size=3) +
scale_fill_gradient(low = "beige", high = "steelblue") +
ylim(c(0, max(nba.m$var2) + 1.5)) +
scale_y_discrete(breaks=y_breaks, labels=y_labels) +
coord_polar(theta="x") +
theme(panel.background=element_blank(),
axis.title=element_blank(),
panel.grid=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank(),
axis.text.y=element_text(size=5))
nba.labs$ang[which(nba.labs$ang < -90)] <- (180+nba.labs$ang)[which(nba.labs$ang < -90)]
#### Representation graphique ####
p3发布于 2021-05-03 09:32:45
你的例子数据与你在这个问题和之前的问题中使用的"nba“例子有很大的不同。这就是为什么你有这么多麻烦的原因。以下是三种可视化实际数据的方法:
1.)Tidyverse geom_tile()方法:
library(tidyverse)
#install.packages("vroom")
library(vroom)
#install.packages("ggrepel")
library(ggrepel)
df <- vroom(file = "example.txt")
df %>%
pivot_longer(cols = -c(Name), names_to = "category") %>%
ggplot(aes(x = Name, y = category, fill = value)) +
geom_tile(colour = "white") +
geom_text(aes(label = ifelse(Name == "BCI0503", category, "")),
nudge_x = -0.5) +
geom_text_repel(aes(label = ifelse(category == "TEM", Name, "")),
nudge_y = 2) +
scale_fill_gradient(low = "beige", high = "red", breaks = c(0, 1)) +
coord_polar(theta="x") +
theme_void()

这看起来不太好--你可以在中间做一个“洞”,但我认为这种类型的图不适合你的数据。
2.) Circlize圆图
#install.packages("circlize")
library(circlize)
mat = data.matrix(df)[,2:9]
rownames(mat) <- df$Name
col_fun1 = colorRamp2(c(0, 1), c("beige", "red"))
circos.par(gap.after = c(20))
circos.heatmap(mat, col = col_fun1,
rownames.side = "outside",
track.height = 0.4)
circos.track(track.index = get.current.track.index(),
panel.fun = function(x, y) {
if(CELL_META$sector.numeric.index == 1) { # the last sector
cn = colnames(mat)
n = length(cn)
circos.text(rep(CELL_META$cell.xlim[2], n) + convert_x(1, "mm"),
1:n - 0.5, cn,
cex = 0.5, adj = c(0, 0.5), facing = "inside")
}
}, bg.border = NA)

这是更好的,但仍然不是很好。我认为问题在于您的“计数”要么是0,要么是1--我认为另一种方法更适合这种类型的数据: UpSetR图
3.) UpSetR plot
#install.packages("UpSetR")
library(UpSetR)
df_int <- df %>%
mutate(across(c(2:9), as.integer)) %>%
as.data.frame()
upset(df_int, order.by = "freq", sets.bar.color = "#56B4E9")

这就是我如何可视化这种类型的数据,但很明显,这取决于你最终想要如何描述它。
如果您在原始问题中包含了实际数据的样本,则此答案将需要大约10分钟,而不是一个小时。在以后的问题中,请确保您的示例数据集与您的实际数据准确匹配。
https://stackoverflow.com/questions/67342060
复制相似问题