I’m graphing a large number of bars in a barplot (>1000), and want to color a subset of them black to highlight them. However, with this large number I run into what I think is an issue with screen resolution. When I zoom in some black bars appear or disappear (notice the rug plot without corresponding black bars above it), and white bars appear (which should not be there).
My priority is the black bars. Does anyone have advice to ensure all of the black bars appear? The rug plot at the bottom has the same issue where the rug dashes with disappear and reappear depending on whether I zoom in or out. I’ve tried overlaying points on top, which works but the aesthetic is pretty terrible and much less intuitive.
Thank you!
Shawn.
# Load library and create dummy data
library(ggplot2)
library(dplyr)
set.seed(1020)
a <- data.frame(graph = seq(2000),order=rep(seq(1000),2),facet=c(rep('one',1000),rep('two',1000)),col=sample(2000) %% 100 == 0)
# Create plot with facets
testPlot1 <- ggplot(a, aes(x = order, y = graph)) + geom_bar(aes(fill=col),stat = "identity",na.rm=T) +
theme_classic() + ggtitle('Plot A with facets') +
scale_fill_manual(values=c(`FALSE`='lightgrey',`TRUE`='black')) +
geom_rug(sides='b',aes(color=col)) +
scale_color_manual(values=c(`FALSE`='white',`TRUE`='black')) + guides(color='none',x='none') +
facet_wrap(~facet,scales='free_x')
print(testPlot1)
# Session Info
sessionInfo()
# R version 4.4.0 (2024-04-24)
# Platform: x86_64-pc-linux-gnu
# Running under: Ubuntu 24.04 LTS
#
# Matrix products: default
# BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
# LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#
# locale:
# [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8
# [6] LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
# [11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#
# time zone: Etc/UTC
# tzcode source: system (glibc)
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] dplyr_1.1.4 ggplot2_3.5.1
#
# loaded via a namespace (and not attached):
# [1] labeling_0.4.3 utf8_1.2.4 R6_2.5.1 tidyselect_1.2.1 farver_2.1.2 magrittr_2.0.3
# [7] gtable_0.3.5 glue_1.7.0 tibble_3.2.1 pkgconfig_2.0.3 generics_0.1.3 lifecycle_1.0.4
# [13] cli_3.6.2 fansi_1.0.6 scales_1.3.0 grid_4.4.0 vctrs_0.6.5 withr_3.0.0
# [19] compiler_4.4.0 rstudioapi_0.16.0 tools_4.4.0 munsell_0.5.1 pillar_1.9.0 colorspace_2.1-0
# [25] rlang_1.1.4
Image of plot
Shawn Foley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.