Entering edit mode
Hello I am trying to plot confidence interval in a Gviz plot without having this kind of connected effect always displayed by GViz
(see example below) is there a simple way to get this kind of confidence interval plotted in a base pair fashion?
# Load required libraries
library(GViz)
library(GenomicRanges)
# Example data: Genetic positions, point estimates, and confidence intervals
data <- data.frame(
chromosome = "chr1", # Modify for different chromosomes
position = c(100000, 200000, 300000, 400000, 500000), # Base pair positions
estimate = c(0.2, -0.3, 0.5, -0.1, 0.4), # Point estimates
ci_width = c(0.05, 0.1, 0.08, 0.06, 0.09) # Half-width of confidence intervals
)
# Compute confidence interval bounds
data$ci_lower <- data$estimate - data$ci_width
data$ci_upper <- data$estimate + data$ci_width
# Create GenomicRanges objects
gr_points <- GRanges(seqnames = data$chromosome,
ranges = IRanges(start = data$position, end = data$position),
estimate = data$estimate)
gr_ci <- GRanges(seqnames = data$chromosome,
ranges = IRanges(start = data$position, end = data$position),
ci_lower = data$ci_lower,
ci_upper = data$ci_upper)
# DataTrack for point estimates (scatter plot)
points_track <- DataTrack(gr_points,
name = "Effect Sizes",
type = "p", # 'p' for points
col = "blue",
cex = 1.5, # Point size
pch = 19) # Solid circles
# DataTrack for confidence intervals (lines)
ci_track <- DataTrack(gr_ci,
name = "Confidence Intervals",
type = "line", # 'line' for error bars
col = "black",
lwd = 2, # Line width
from = data$ci_lower, # Lower bound
to = data$ci_upper) # Upper bound
# Genome axis track for better visualization
gtrack <- GenomeAxisTrack()
# Chromosome ideogram track (Optional, requires BSgenome package)
itrack <- IdeogramTrack(genome = "hg19", chromosome = "chr1")
# Plot the GViz tracks
plotTracks(list(itrack, gtrack, ci_track, points_track),
from = min(data$position) - 50000,
to = max(data$position) + 50000,
main = "Effect Sizes with Confidence Intervals")