Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: There is no numeric column in your data frame which calculation of ylim depends on. Or you can set ylim explicitely. #405

Open
Calle027 opened this issue Feb 4, 2025 · 0 comments

Comments

@Calle027
Copy link

Calle027 commented Feb 4, 2025

Hi there,

I'm very new to creating circular plots! :)

I have been trying to create a circular plot with mixed results.

I'm trying to make a plot with stacked bars for ancestry values in one track, diversity values as points in a separate track, along with a yaxis label for each along chr_1, and the x axis would be the chrom labels and track. Furthermore, I'm trying to create black dashed boxes around relevant genes in my study.

Here is what the code looks like:

plot_single_population_circle <- function(
genome_info_bed,
bed_hsp_filtered,
diversity_win,
ancestry_win,
diversity_col,
ancestry_cols,
ancestry_labels,
pop_name,
outfile
) {
diversity_win$pi <- as.numeric(diversity_win$pi)
ancestry_win$African <- as.numeric(ancestry_win$African)
ancestry_win$EastEurope <- as.numeric(ancestry_win$EastEurope)
ancestry_win$MiddleEast <- as.numeric(ancestry_win$MiddleEast)
ancestry_win$WestEurope <- as.numeric(ancestry_win$WestEurope)

ragg::agg_png(outfile, width=12, height=12, units="in", res=300)
op <- par(no.readonly = TRUE)
par(mar = c(1, 1, 1, 1), oma = c(0, 0, 0, 0))

circos.clear()
circos.par(gap.degree = 5)
circos.genomicInitialize(genome_info_bed, major.by = 5e6)

circos.genomicTrackPlotRegion(
genome_info_bed,
panel.fun = function(region, value, ...) {
circos.genomicLabels(
genome_info_bed,
labels.column = 1,
side = "outside",
niceFacing = TRUE
)
},
track.height = 0.05
)

circos.genomicTrack(
diversity_win,
panel.fun = function(region, value, ...) {
circos.genomicPoints(region, value$pi, pch=16, col=diversity_col, cex=0.5)
},
track.height = 0.1
)

circos.yaxis(side = "left")

circos.genomicTrack(
ancestry_win,
panel.fun = function(region, value, ...) {
ancestry_cols <- c("red", "gold", "cyan2", "black")
running_bottom <- 0
for(i in seq_along(ancestry_cols)) {
height <- value[[ i ]] # the fraction
ybottom <- running_bottom
ytop <- ybottom + height
circos.genomicRect(
region,
ybottom = ybottom,
ytop = ytop,
col = ancestry_cols[i],
border = NA
)
running_bottom <- ytop
}
},
track.height = 0.15
)

circos.yaxis(side = "right")

gene_bins <- bed_hsp_filtered %>%
mutate(bin = floor(start / 1e4))

circos.genomicTrackPlotRegion(
gene_bins,
panel.fun = function(region, value, ...) {
circos.genomicRect(
region,
ybottom = 0,
ytop = 1,
border = "black",
lty = 2,
col = NA
)
},
track.height = 0.2
)

legend (under construction)

pushViewport(viewport(x = unit(0.85, "npc"), y = unit(0.85, "npc"),
width=unit(0.15, "npc"), height=unit(0.15,"npc"),
just=c("left", "top")))
grid.text("Ancestry", x=unit(0, "npc"), y=unit(1, "npc"), just=c("left","top"))
popViewport()

par(op)
dev.off()
}

SoCal

plot_single_population_circle(
genome_info_bed = genome_info_bed,
bed_hsp_filtered = bed_hsp_filtered,
diversity_win = diversity_socal_win,
ancestry_win = ancestry_socal_win,
diversity_col = "#ab2f5e",
ancestry_cols = c("red","gold","cyan2","black"),
ancestry_labels = c("African","EastEurope","MiddleEast","WestEurope"),
pop_name = "SoCal",
outfile = "socal_circle_plot.png"
)

Here is the structure of my data:

str(genome_info_bed)
'data.frame': 16 obs. of 3 variables:
$ chr : Ord.factor w/ 16 levels "chr_1"<"chr_2"<..: 1 2 3 4 5 6 7 8 9 10 ...
$ start: num 1 1 1 1 1 1 1 1 1 1 ...
$ end : num 27754200 16089512 13619445 13404451 13896941 ...
str(bed_hsp_filtered)
'data.frame': 48 obs. of 4 variables:
$ chr : Ord.factor w/ 16 levels "chr_1"<"chr_2"<..: 1 1 1 1 1 1 2 2 2 2 ...
$ start : num 21487433 4746963 19786204 20112992 2084242 ...
$ end : num 21487932 4749151 19786892 20115486 2089152 ...
$ HSP_MAP_ID: chr "HscB" "Hsf" "Hsf-bp1" "Hsp83" ...
str(diversity_socal_win)
'data.frame': 19813 obs. of 5 variables:
$ chr : Ord.factor w/ 16 levels "chr_1"<"chr_2"<..: 1 1 1 1 1 1 1 1 1 1 ...
$ start: num 5485 11396 65075 74409 82614 ...
$ end : num 6470 11420 68754 79797 83894 ...
$ pi : num 0.311 0.48 0.497 0.506 0.466 ...
$ bin : num 0 1 6 7 8 9 10 13 14 15 ...
str(ancestry_socal_win)
'data.frame': 21960 obs. of 9 variables:
$ chr : Ord.factor w/ 16 levels "chr_1"<"chr_2"<..: 1 1 1 1 1 1 1 1 1 1 ...
$ start : num 3536 10089 20295 30562 40549 ...
$ end : num 9969 19411 29572 39513 49900 ...
$ African : num 0.303 0.333 0.333 0.333 0.333 ...
$ EastEurope: num 0.313 0.4 0.4 0.4 0.4 ...
$ MiddleEast: num 0.0562 0 0 0 0 ...
$ WestEurope: num 0.328 0.267 0.267 0.267 0.267 ...
$ bin : num 0 1 2 3 4 5 6 7 8 9 ...
$ total : num 1 1 1 1 1 ...

"Error: There is no numeric column in your data frame which calculation of ylim depends on. Or you can set ylim explicitely."

I'm not understanding the error since all of my variables are numeric besides chr, which should be fine? I have tried setting ylim explicitly and I still get the same error.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant