### Install jjAnno Package Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This snippet shows how to install the jjAnno package from GitHub using the devtools package. It also demonstrates loading the library for use. ```R # install.packages("devtools") devtools::install_github("junjunlab/jjAnno") library(jjAnno) ``` -------------------------------- ### Install jjAnno Package Source: https://github.com/junjunlab/jjanno/blob/master/README.md Provides instructions for installing the jjAnno R package from CRAN and the development version from GitHub. It requires the 'devtools' package for GitHub installation. ```r # install from cran install.packages("jjAnno") # install.packages("devtools") devtools::install_github("junjunlab/jjAnno") ``` -------------------------------- ### Get and Show Color Palettes with useMyCol Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code demonstrates how to use the 'useMyCol' function from the jjAnno package to display all available color palettes and to draw specific color palettes for visualization. ```R # show all plattes useMyCol(showAll = T) # plot colors show_col(useMyCol('stallion',20)) # ironMan show_col(useMyCol('ironMan',15)) # whitePurple show_col(useMyCol('whitePurple',9)) ``` -------------------------------- ### Get and Display Color Palettes with useMyCol (R) Source: https://context7.com/junjunlab/jjanno/llms.txt The useMyCol function from the jjAnno package provides access to curated color palettes for data visualization. It allows users to retrieve a specified number of colors from named palettes (discrete or continuous) and can also display all available palettes. ```r library(jjAnno) # Get 5 colors from stallion palette colors <- useMyCol(platte = 'stallion2', n = 5) # Returns: "#D51F26" "#272E6A" "#208A42" "#89288F" "#F47D2B" # Display all available palettes useMyCol(showAll = TRUE) # Use different palettes bear_colors <- useMyCol(platte = 'bear', n = 10) horizon_colors <- useMyCol(platte = 'horizon', n = 10) kelly_colors <- useMyCol(platte = 'kelly', n = 15) # Apply palette to annotations data(p) annoRect(object = p, annoPos = 'top', xPosition = c(1:8), pFill = useMyCol(platte = 'ironMan', n = 8), pCol = "white") ``` -------------------------------- ### Add Point Annotations to Plots with annoPoint Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code demonstrates the use of the 'annoPoint' function from jjAnno to add point annotations to a ggplot object. It shows examples of positioning annotations at the top, right, and left, and adjusting parameters like point size and shape. ```R # default plot annoPoint(object = p, annoPos = 'top', xPosition = c(1:10)) # specify yPosition annoPoint(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = rep(c(2,4,2,6,4),each = 2)) # add right annoPoint(object = p, annoPos = 'right', yPosition = c(1:10)) # left annoPoint(object = p, annoPos = 'left', yPosition = c(1:10)) # supply xPosition to ajust annoPoint(object = p, annoPos = 'right', yPosition = c(1:10), xPosition = 0.3) # change point size and shape annoPoint(object = p, annoPos = 'top', xPosition = c(1:10), ptSize = 2, ptShape = 25) ``` -------------------------------- ### Annotate with Manual Coordinates Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds rectangular annotations to a plot using manually supplied coordinates. The 'annoManual = T' argument indicates that the xPosition and yPosition lists define the exact start and end points for each rectangle. Dependencies: Requires a plot object 'p', annoRect function, and manual coordinate lists. ```R # supply your own coordinates to annotate annoRect(object = p, annoPos = 'top', annoManual = T, xPosition = list(c(1,6), c(5,10)), yPosition = c(11,11.5), pCol = rep('black',2), lty = 'solid', lwd = 2) ``` -------------------------------- ### Load Image Files for Annotation Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet shows how to load multiple image files from the 'extdata/animal-img/' directory within the 'jjAnno' package using system.file. These image paths are then stored in a character vector 'imgs' for use with the annoImage function. ```r img1 <- system.file("extdata/animal-img/", "1.jpg", package = "jjAnno") img2 <- system.file("extdata/animal-img/", "2.jpg", package = "jjAnno") img3 <- system.file("extdata/animal-img/", "3.jpg", package = "jjAnno") img4 <- system.file("extdata/animal-img/", "4.jpg", package = "jjAnno") img5 <- system.file("extdata/animal-img/", "5.jpg", package = "jjAnno") img6 <- system.file("extdata/animal-img/", "6.jpg", package = "jjAnno") img7 <- system.file("extdata/animal-img/", "7.jpg", package = "jjAnno") img8 <- system.file("extdata/animal-img/", "8.jpg", package = "jjAnno") img9 <- system.file("extdata/animal-img/", "9.jpg", package = "jjAnno") img10 <- system.file("extdata/animal-img/", "10.jpg", package = "jjAnno") imgs <- c(img1,img2,img3,img4,img5,img6,img7,img8,img9,img10) ``` -------------------------------- ### Create a Basic ggplot with jjAnno Compatibility Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code creates a basic ggplot object with sample data. It includes essential theme settings and `coord_cartesian(clip = 'off')` to ensure compatibility with jjAnno's annotation functions. ```R df <- data.frame(x = 1:10,y = sample(1:10,10), x1 = LETTERS[1:10]) library (ggplot2) p <- ggplot(df, aes(x,x1)) + geom_point(aes(size = x,color = x,alpha = x)) + theme_bw(base_size = 14) + scale_x_continuous(breaks = seq(1,10,1)) + scale_color_gradient(low = 'grey50',high = '#339933',name = '') + coord_cartesian(clip = 'off') + theme(aspect.ratio = 1, plot.margin = margin(t = 1,r = 1,b = 1,l = 1,unit = 'cm'), axis.text.x = element_text(vjust = unit(-1.5,'native')), legend.position = 'left') + xlab('') + ylab('') p ``` -------------------------------- ### Create ggplot with GO Data Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Generates a ggplot object using the 'pgo' dataset, visualizing terms against log10PValue. It includes custom color gradients, discrete y-axis positioning, and specific x-axis breaks and limits. Dependencies: Requires 'ggplot2', 'dplyr' (implicitly via data manipulation if any), and the 'pgo' dataset. ```R # Plot pgo <- ggplot(df1,aes(x = log10PValue,y = Term)) + geom_point(aes(size = log10PValue, color = log10PValue)) + scale_color_gradient2(low = 'blue',mid = 'green',high = 'red', name = '',midpoint = 2.1) + scale_y_discrete(position = 'right') + scale_x_continuous(breaks = seq(0,2.8,0.4),limits = c(0,2.8)) + theme_grey(base_size = 14) + theme(legend.position = 'left', plot.margin = margin(t = 1,r = 1,b = 1,l = 1,unit = 'cm'), aspect.ratio = 2.5 ) + coord_cartesian(clip = 'off') + ylab('') ``` -------------------------------- ### Create Triangle Annotations with `annoTriangle` Source: https://context7.com/junjunlab/jjanno/llms.txt Demonstrates how to create triangular gradient annotations using `annoTriangle`, useful for showing gradients or transitions. This function supports various triangle orientations, color fills, border customization, and gradient steps. Dependencies include `jjAnno` and `ggplot2`. ```r library(jjAnno) library(ggplot2) data(p) # Adjust plot margins to accommodate annotation p1 <- p + theme(plot.margin = margin(t = 2, unit = 'cm')) # Basic triangle annotation annoTriangle(object = p1, annoPos = 'top', xPosition = c(0, 10.5), fillCol = c("#3361A5", "#248AF3", "#14B3FF", "#88CEEF", "#C1D5DC", "#EAD397", "#FDB31A", "#E42A2A", "#A31D1D"), nCol = 100) # Adjusted positioning annoTriangle(object = p1, annoPos = 'top', xPosition = c(0.5, 10.5), yPosition = c(10.8, 11.5), triangleType = "RD", fillCol = c("blue", "white", "red"), nCol = 50) # Triangle with border annoTriangle(object = p1, annoPos = 'top', xPosition = c(0.5, 10.5), yPosition = c(10.8, 11.5), fillCol = c("#000075", "#2E00FF", "#9408F7", "#C729D6", "#FA4AB5", "#FF6A95", "#FF8B74", "#FFAC53", "#FFCD32", "#FFFF60"), nCol = 100, addBorder = TRUE, borderCol = "black", lwd = 2.5, lty = 1) # Different triangle types annoTriangle(object = p1, annoPos = 'top', xPosition = c(0.5, 10.5), yPosition = c(10.8, 11.5), triangleType = "LU", fillCol = c("green", "yellow"), nCol = 80) ``` -------------------------------- ### Add Multiple Sequential Rect Annotations Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Demonstrates adding multiple rectangular annotations sequentially to a plot. Each call to annoRect can build upon the previous one, allowing for complex annotated visualizations. Dependencies: Requires a plot object 'p', the annoRect function, and potentially results from prior annoRect calls. ```R # add multiple p1 <- annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5), rectWidth = 0.9, pCol = rep('black',10), pFill = rep('grey80',10), lty = 'dashed', lwd = 2) # add second annotation p2 <- annoRect(object = p1, annoPos = 'right', yPosition = c(1:10), xPosition = c(10.5,11), rectWidth = 0.8) # add third annotation annoRect(object = p2, annoPos = 'top', xPosition = c(1:10), yPosition = c(11.8,12.3), rectWidth = 0.8) ``` -------------------------------- ### Add Images with `annoImage` Source: https://context7.com/junjunlab/jjanno/llms.txt Explains how to embed external image files (JPEG, PNG) as annotations around plot boundaries using `annoImage`. This function is useful for adding icons or logos. It supports various positioning options and image size adjustments. Dependencies include `jjAnno` and `ggplot2`. ```r library(jjAnno) library(ggplot2) data(p) # Define image paths img1 <- system.file("extdata/animal-img/", "1.jpg", package = "jjAnno") img2 <- system.file("extdata/animal-img/", "2.jpg", package = "jjAnno") img3 <- system.file("extdata/animal-img/", "3.jpg", package = "jjAnno") img4 <- system.file("extdata/animal-img/", "4.jpg", package = "jjAnno") img5 <- system.file("extdata/animal-img/", "5.jpg", package = "jjAnno") img6 <- system.file("extdata/animal-img/", "6.jpg", package = "jjAnno") img7 <- system.file("extdata/animal-img/", "7.jpg", package = "jjAnno") img8 <- system.file("extdata/animal-img/", "8.jpg", package = "jjAnno") img9 <- system.file("extdata/animal-img/", "9.jpg", package = "jjAnno") img10 <- system.file("extdata/animal-img/", "10.jpg", package = "jjAnno") imgs <- c(img1, img2, img3, img4, img5, img6, img7, img8, img9, img10) # Add images at top of plot annoImage(object = p, annoPos = 'top', xPosition = c(1:10), images = imgs, yPosition = c(11, 12), imgWidth = 1, imgHeight = 1) # Adjusted width for tighter spacing annoImage(object = p, annoPos = 'top', xPosition = c(1:10), images = imgs, yPosition = c(11, 11.8), segWidth = 0.8, imgWidth = 0.9, imgHeight = 0.9) # Add images to right side annoImage(object = p, annoPos = 'right', yPosition = c(1:10), images = imgs, xPosition = c(11, 11.8), segWidth = 0.8, imgWidth = 0.8, imgHeight = 0.8) # Manual positioning for custom layouts annoImage(object = p, annoPos = 'top', annoManual = TRUE, xPosition = list(c(1, 3, 5, 7, 9), c(2, 4, 6, 8, 10)), yPosition = list(c(11, 12), c(11.5, 12.5)), images = imgs[1:10]) ``` -------------------------------- ### Create Branched Segments with `annoSegment` Source: https://context7.com/junjunlab/jjanno/llms.txt Demonstrates how to create complex, branched segments for hierarchical grouping using the `annoSegment` function. It allows for manual positioning, branch direction, and segment length customization. Dependencies include the `jjAnno` package. ```r annoSegment(object = pdot, annoPos = 'top', annoManual = TRUE, xPosition = list(c(1, 3, 4, 7, 9, 11, 12, 15, 17, 19, 20), c(2, 3, 6, 8, 10, 11, 14, 16, 18, 19, 21)), yPosition = 9, segWidth = 0.8, pCol = rep('black', 11), addBranch = TRUE, branDirection = -1, branRelSegLen = 0.5, lwd = 3) annoSegment(object = p, annoPos = 'top', xPosition = c(1:5, 6:10), segWidth = c(rep(5, 1), rep(5, 1)), addText = TRUE, textLabel = c("Group A", "Group B"), textSize = 10, textCol = c("red", "blue"), lwd = 10) annoSegment(object = p, annoPos = 'right', yPosition = c(1:10), lwd = 4, mArrow = arrow(length = unit(0.2, "inches"), type = "closed")) ``` -------------------------------- ### Add Multiple Annotations with annoPoint Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code illustrates how to layer multiple annotations onto a plot using the 'annoPoint' function. It first adds top annotations and then adds right annotations to the resulting plot object. ```R # add multiple annotations p1 <- annoPoint(object = p, annoPos = 'top', xPosition = c(1:10), ptSize = 2, ptShape = 25) annoPoint(object = p1, annoPos = 'right', yPosition = c(1:10), ptSize = 2, ptShape = 23) ``` -------------------------------- ### Add Simple Image Annotations Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates how to add simple image annotations to a plot using the annoImage function. It specifies the annotation position, x-coordinates, the list of loaded images, and y-positions. This allows for basic image overlays on the plot based on specified coordinates. ```r # add legend annoImage(object = p, annoPos = 'top', xPosition = c(1:10), images = imgs, yPosition = c(11,12)) ``` -------------------------------- ### Manually Annotate with Images Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates manual image annotation using the annoImage function with 'annoManual = T'. It allows for precise control over the placement of multiple images by providing lists of x and y coordinates, and specifies the segment width for the annotations. This is useful for complex image layouts within a plot. ```r # annotate manually annoImage(object = p, annoPos = 'right', yPosition = list(c(1:10), c(1:10)), images = imgs, annoManual = T, xPosition = list(rep(c(11,11.8),each = 5), rep(c(11.8,12.6),each = 5)), segWidth = 0.8) ``` -------------------------------- ### Add Image Annotations to the Bottom Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet illustrates adding image annotations to the bottom of a plot using the annoImage function. It specifies the annotation position as 'botomn' (likely a typo for 'bottom'), x-coordinates, image list, and y-positions relative to the plot's bottom edge, controlling the display of images below the plot. ```r # add to botomn annoImage(object = p, annoPos = 'botomn', xPosition = c(1:10), images = imgs, yPosition = c(-1.2,-0.4), segWidth = 0.8) ``` -------------------------------- ### Annotate GO Plot Manually with Segments Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates manual segment annotation on a Gene Ontology (GO) plot using the annoSegment function. It utilizes 'annoManual = T' to specify custom x and y coordinates, along with custom segment colors. This allows for detailed and specific annotation of GO enrichment results. ```r # annotate mannually annoSegment(object = pgo, annoPos = 'left', annoManual = T, xPosition = rep(-0.15,3), yPosition = list(c(1,6,11), c(5,10,15)), pCol = c('#F5F0BB','#C4DFAA','#90C8AC'), segWidth = 1) ``` -------------------------------- ### Customize Rect Annotation Color and Fill Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation to a plot object with specified border color (pCol) and fill color (pFill). This enables aesthetic customization of the annotations. Dependencies: Requires a plot object 'p', annoRect function, and specified x/yPositions and rectWidth. ```R # change rect color and fill annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5), rectWidth = 0.9, pCol = rep('black',10), pFill = rep('grey80',10)) ``` -------------------------------- ### Add Text Annotation with Segments and Branches in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Combines segment and branch annotations with text labels. The 'addText = T' argument enables text addition, with parameters like 'textLabel', 'textCol', 'textRot', and 'hjust' controlling the text's appearance and placement relative to the segments. ```r # add text text <- c('Mesothelial','Extragonadal','Gonadal','Supporting lineage','Interstitial lineage', 'Testis fate','Early supporting','Granulosa','Sertoli','sPAX8','Mesenchymal') # add text annoSegment(object = P4, annoPos = 'top', annoManual = T, xPosition = list(c(1,3,4,7,9,11,12,15,17,19,20), c(2,3,6,8,10,11,14,16,18,19,21)), yPosition = 9.2, segWidth = 0.8, pCol = rep('black',11), addBranch = T, branDirection = -1, lwd = 3, addText = T, textLabel = text, textCol = c(rep('black',5),'blue',rep('black',5)), textRot = 45, hjust = 0) ``` -------------------------------- ### Add Segment Annotations with jjAnno Source: https://context7.com/junjunlab/jjanno/llms.txt Adds line segment annotations to ggplot2 plots, supporting optional branches, arrows, and text labels. Offers both automatic and manual positioning for creating hierarchical or connected annotations. ```r library(jjAnno) library(ggplot2) data(p) data(pdot) # Basic horizontal segments at top annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), lwd = 5, pCol = c("#D51F26", "#272E6A", "#208A42", "#89288F", "#F47D2B", "#FEE500", "#8A9FD1", "#C06CAB", "#E6C2DC", "#90D5E4")) # Adjusted segment width annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, lwd = 8, lty = 1, alpha = 0.8) ``` -------------------------------- ### Define X and Y Position for Legend in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Specifies the exact x and y coordinates for placing a legend annotation on a plot. This offers precise control over legend placement using 'xPosition' and 'yPosition' arguments. ```r # define x and y position annoLegend(object = p, xPosition = 12, yPosition = 5, labels = paste('legend ',1:5), pch = 21:25, col = 'black', fill = useMyCol('paired',5), textSize = 15) ``` -------------------------------- ### Add Point Annotations with jjAnno Source: https://context7.com/junjunlab/jjanno/llms.txt Adds point markers to ggplot2 plots at specified positions, typically around plot boundaries. Supports automatic positioning, customizable point size, shape, and color. Ideal for marking specific data points or categories. ```r library(jjAnno) library(ggplot2) data(p) # Basic point annotation at top annoPoint(object = p, annoPos = 'top', xPosition = c(1:10)) # Custom y-positions with varying heights annoPoint(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = rep(c(2, 4, 2, 6, 4), each = 2), pCol = c("#D51F26", "#272E6A", "#208A42", "#89288F", "#F47D2B", "#FEE500", "#8A9FD1", "#C06CAB", "#E6C2DC", "#90D5E4"), ptSize = 4, ptShape = 19) # Right side annotation with custom positioning annoPoint(object = p, annoPos = 'right', yPosition = c(1:10), xPosition = 0.3, pCol = rainbow(10), ptSize = 3, ptShape = c(15, 16, 17, 18, 19, 20, 21, 22, 23, 24)) # Left side annotation annoPoint(object = p, annoPos = 'left', yPosition = c(1:10), ptSize = 5, ptShape = 25) ``` -------------------------------- ### Adjust Image Annotation Width Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet shows how to adjust the width of image annotations using the segWidth parameter within the annoImage function. It specifies the annotation position, x-coordinates, image list, and y-positions, alongside the segment width to control the visual size of the images. ```r # change width annoImage(object = p, annoPos = 'top', xPosition = c(1:10), images = imgs, yPosition = c(11,11.8), segWidth = 0.8) ``` -------------------------------- ### Add Partial Rect Annotations Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds specific, non-contiguous rectangular annotations to a plot. This is useful for highlighting selected data points or ranges. Dependencies: Requires a plot object 'p', annoRect function, and specified x/yPositions. ```R # only add some annotations annoRect(object = p, annoPos = 'top', xPosition = c(1,3,5,7,9), yPosition = c(11,11.5)) ``` -------------------------------- ### Supply Own Coordinates for Segment Annotations Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet shows how to manually define the coordinates for segment annotations using the annoSegment function. It allows for precise placement by providing a list of x and y coordinates, enabling custom annotation layouts. The function uses 'annoManual = T' to enable manual coordinate input. ```r # supply your own coordinates to annotate annoSegment(object = p, annoPos = 'top', annoManual = T, xPosition = list(c(1,6), c(5,10)), yPosition = 11, pCol = c('green','orange')) ``` -------------------------------- ### Add Rectangle Annotations with jjAnno Source: https://context7.com/junjunlab/jjanno/llms.txt Adds rectangle annotations (standard, rounded, gradient-filled) to ggplot2 plots. It supports automatic positioning based on data ranges, custom colors, borders, and text labels. Useful for highlighting regions or adding categorical labels. ```r library(jjAnno) library(ggplot2) # Load sample data data(p) # Basic rectangle annotation at top of plot annoRect(object = p, annoPos = 'top', xPosition = c(1:10)) # Custom positioning with specific colors annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11, 11.5), pFill = c("#D51F26", "#272E6A", "#208A42", "#89288F", "#F47D2B", "#FEE500", "#8A9FD1", "#C06CAB", "#E6C2DC", "#90D5E4"), pCol = "black", lwd = 2) + scale_y_discrete(expand = c(0, 0)) # Gradient-filled rectangles with borders annoRect(object = p, annoPos = 'right', yPosition = c(1:10), xPosition = c(11, 12), continuesRect = TRUE, border = TRUE, conRectCol = list(c("white", "red"), c("white", "blue")), conRectColBin = 20, interpolate = TRUE) # Rounded rectangles with text labels annoRect(object = p, annoPos = 'top', xPosition = c(1:10), roundRect = TRUE, roundRadius = 0.15, addText = TRUE, textLabel = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"), textSize = 12, textCol = "white") # Group-based annotation using aesthetic mapping annoRect(object = pgo, annoPos = 'top', aesGroup = TRUE, aesGroName = "group", rectWidth = 1, addText = TRUE, textSize = 10) ``` -------------------------------- ### Add Branch to Segment Annotations with Manual Coordinates Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates adding branches to segment annotations with manually specified coordinates using the annoSegment function. It controls branch direction, line width, and segment width for customized visual representation. The 'annoManual = T' argument is crucial for providing custom coordinate lists. ```r # add branch to plot annoSegment(object = p, annoPos = 'top', annoManual = T, addBranch = T, lwd = 3, segWidth = 0.5, xPosition = list(c(1,6), c(5,10)), yPosition = c(11,11), pCol = c('green','orange'), branDirection = -1) ``` -------------------------------- ### Add Dashed Rectangle Annotation in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation with specific styling, including dashed borders ('lty = "dashed"') and custom line width ('lwd'). This function is useful for highlighting specific regions with distinct visual cues. ```r # add rect2 P3 <- annoRect(object = P2, annoPos = 'left', annoManual = T, yPosition = list(c(2.5), c(6.5)), xPosition = c(-3.5,16.5), pCol = 'black', pFill = 'transparent', lty = 'dashed', lwd = 3) ``` -------------------------------- ### Annotate Segments with Text Color and Branch Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates how to use the annoSegment function to add segment annotations to a plot. It customizes text color, position, rotation, and adds a branch to the annotation. The function takes an object 'p' as input and specifies annotation properties like position, segment width, and text labels. ```r # change text color annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4, branDirection = -1, addText = T, textLabel = paste0('anno',1:10,sep = ''), textRot = 45, textSize = 15, textHVjust = 0.5, textCol = rep('grey50',10)) ``` -------------------------------- ### Add Segment Annotation with Branch in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds segment annotations that include branches, controlled by 'addBranch = T' and 'branDirection'. This is useful for creating flow-like diagrams or annotations originating from specific points. ```r # add branch P4 <- annoSegment(object = P3, annoPos = 'top', annoManual = T, xPosition = list(c(1,3,4,7,9,11,12,15,17,19,20), c(2,3,6,8,10,11,14,16,18,19,21)), yPosition = 9.2, segWidth = 0.8, pCol = rep('black',11), addBranch = T, branDirection = -1, lwd = 3) ``` -------------------------------- ### Add Rectangular Annotations to Plot Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 The annoRect function adds rectangular annotations to a plot. It allows customization of position, color, and width. The function can accept either fixed positions or manual coordinates for the rectangles. ```R # another example annotation GO terms annoRect(object = pgo, annoPos = 'right', yPosition = c(1:15), pCol = rep('transparent',15), pFill = rep(c('#F5F0BB','#C4DFAA','#90C8AC'),each = 5), xPosition = c(3,10), rectWidth = 1) ``` ```R # annotate mannually annoRect(object = pgo, annoPos = 'right', annoManual = T, xPosition = c(3,10), yPosition = list(c(0.5,5.5,10.5), c(5.5,10.5,15.5)), pCol = rep('black',3), pFill = c('#F5F0BB','#C4DFAA','#90C8AC')) ``` -------------------------------- ### Set Rectangular Annotation Width Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation to a plot object, allowing explicit control over the width of the rectangles. This ensures annotations fit appropriately within the plot's design. Dependencies: Requires a plot object 'p', annoRect function, and specified x/yPositions. ```R # adjust rectWidth annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5), rectWidth = 0.9) ``` -------------------------------- ### Add Image Annotations to the Right Side Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates adding image annotations to the right side of a plot using the annoImage function. It defines the annotation position, y-coordinates, image list, x-coordinates, and segment width to control the placement and appearance of the images on the right edge of the plot. ```r # add to right annoImage(object = p, annoPos = 'right', yPosition = c(1:10), images = imgs, xPosition = c(11,11.8), segWidth = 0.8) ``` -------------------------------- ### Specify Multiple Y-Positions for Annotations Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds rectangular annotations to a plot where multiple y-axis ranges can be specified for each annotation. This allows for annotations to span vertically across different regions. Dependencies: Requires a plot object 'p', annoRect function, and list-formatted xPosition and yPosition. ```R # multiple yPosition annoRect(object = p, annoPos = 'top', annoManual = T, xPosition = list(c(1,6), c(5,10)), yPosition = list(c(11,11.5), c(11.5,12)), pCol = rep('black',2), lty = 'solid', lwd = 2) ``` -------------------------------- ### Modify Alpha Transparency of Rect Annotation Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation to a plot object while adjusting its transparency (alpha). This is useful for layering annotations without obscuring plot details. Dependencies: Requires a plot object 'p', annoRect function, and specified x/yPositions. ```R # change color alpha annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5), alpha = 0.5) ``` -------------------------------- ### Add Default Rect Annotation Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a default rectangular annotation to a plot object. The annotation is positioned at the top of the plot and spans the specified x-axis positions. Dependencies: Requires a plot object 'p' and the annoRect function. ```R # default plot annoRect(object = p, annoPos = 'top', xPosition = c(1:10)) ``` -------------------------------- ### Adjust Y-Position of Rect Annotation Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation to a plot object with adjusted y-axis positions. This allows for finer control over the vertical placement of the annotation. Dependencies: Requires a plot object 'p', annoRect function, and specified xPosition. ```R # adjust yPosition annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5)) ``` -------------------------------- ### Modify Rect Annotation Line Type and Width Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a rectangular annotation to a plot object, customizing the line type (lty) and line width (lwd) of the rectangle borders. This allows for distinct visual representation of annotations. Dependencies: Requires a plot object 'p', annoRect function, and specified x/yPositions, rectWidth, pCol, and pFill. ```R # change rect lty and lwd annoRect(object = p, annoPos = 'top', xPosition = c(1:10), yPosition = c(11,11.5), rectWidth = 0.9, pCol = rep('black',10), pFill = rep('grey80',10), lty = 'dashed', lwd = 2) ``` -------------------------------- ### Add Rectangle Annotations to Plot in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds rectangular annotations to a plot. It allows manual positioning using 'annoManual = T' and defining y-position ranges. Customization includes border color ('pCol'), fill color ('pFill'), and transparency ('alpha'). ```r # add rect1 P2 <- annoRect(object = P1, annoPos = 'left', annoManual = T, yPosition = list(c(0.5,4.5), c(4.5,8.5)), xPosition = c(-3.5,0.3), pCol = rep('white',2), pFill = useMyCol('calm',2), alpha = 0.5) ``` -------------------------------- ### Add Segment Annotations to Plot in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds segment annotations to a plot, often used for indicating ranges or connections. It supports specifying positions via 'annoPos', 'xPosition', and 'yPosition', and customization of segment color and width. ```r # add segment P1 <- annoSegment(object = pdot, annoPos = 'top', xPosition = c(1:21), yPosition = 8.8, segWidth = 0.7, pCol = c(useMyCol('stallion',20),'orange')) ``` -------------------------------- ### Add Multiple Shapes to Legend in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Creates a legend annotation that displays multiple shapes. The 'pch' argument can accept a vector of shape codes to cycle through. This is useful for legends representing data with varied symbol types. ```r # multiple shapes annoLegend(object = p, relPos = c(0.2,0.9), labels = paste('legend ',1:5), pch = 21:25, col = 'black', fill = useMyCol('paired',5), textSize = 15) ``` -------------------------------- ### Change Segment Y-Position with Custom Colors Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet illustrates modifying the vertical position (yPosition) of segment annotations using the annoSegment function. It also allows for custom colorization of segments using a specified color palette. The function takes an object 'p' and defines annotation placement and segment properties. ```r # change yPosition annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, pCol = useMyCol('horizon',10), yPosition = 5) ``` -------------------------------- ### Disable Plot Clipping in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet demonstrates how to disable clipping for plots using coord_cartesian(clip = 'off'). This is often necessary when adding annotations outside the main plot area. ```R coord_cartesian(clip = 'off') ``` -------------------------------- ### Add Legend Annotation to Plot in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds a legend annotation to a plot object. It allows customization of labels, shapes (pch), colors (col), fill colors, and text size. Dependencies include the object 'p' and potentially a color palette function like 'useMyCol'. ```r # add legend annoLegend(object = p, labels = paste('legend ',1:5), pch = 21, col = 'black', fill = useMyCol('paired',5), textSize = 15) ``` -------------------------------- ### Add Segment Annotations to Plot Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 The annoSegment function adds segment annotations to a plot, which can be positioned at the top, bottom, or right side. It supports customization of segment width, line width, arrows, branches, and text labels with various formatting options. ```R # default plot annoSegment(object = p, annoPos = 'top', xPosition = c(1:10)) ``` ```R # adjust rectWidth annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8) ``` ```R library(ggplot2) # add segments with arrow annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.9, lwd = 1, mArrow = arrow(ends = 'both', length = unit(0.2,'cm'), type = 'closed')) ``` ```R # change rect color and fill annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, pCol = useMyCol('horizon',10)) ``` ```R # add branch annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4) ``` ```R # change branch direction annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4, branDirection = -1) ``` ```R # add to botomn annoSegment(object = p, annoPos = 'botomn', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4) ``` ```R # add to right annoSegment(object = p, annoPos = 'right', yPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4, branDirection = -1) ``` ```R # add to botomn and make branch taged with arrow annoSegment(object = p, annoPos = 'botomn', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 3, bArrow = arrow(length = unit(0.2,'cm'), ends = 'last')) ``` ```R # add text label annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4, branDirection = -1, addText = T, textLabel = paste0('anno',1:10,sep = ''), textRot = 0, textSize = 15) ``` ```R # add text space from segments annoSegment(object = p, annoPos = 'top', xPosition = c(1:10), segWidth = 0.8, addBranch = T, lwd = 4, branDirection = -1, addText = T, textLabel = paste0('anno',1:10,sep = ''), textRot = 45, textSize = 15, textHVjust = 0.5) ``` -------------------------------- ### Add Rect Annotation to the Right Side Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Adds rectangular annotations to the right side of a plot. This is useful for adding supplementary information or visual markers to the plot's periphery. Dependencies: Requires a plot object 'p', annoRect function, and specified yPosition, xPosition, and rectWidth. ```R # add to right annoRect(object = p, annoPos = 'right', yPosition = c(1:10), xPosition = c(10.5,11), rectWidth = 0.8) ``` -------------------------------- ### Add Segment Annotations to the Right Side Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 This R code snippet shows how to add segment annotations to the right side of a plot using the annoSegment function. It specifies the annotation position ('right') and controls the y-position and segment width for the annotations. This is useful for adding supplementary information to the right of the main plot area. ```r # add to right annoSegment(object = p, annoPos = 'right', yPosition = c(1:10), segWidth = 0.8) ``` -------------------------------- ### Change Legend Position on Plot in R Source: https://github.com/junjunlab/jjanno/wiki/jjAnno-0.0.1 Modifies the position of a legend annotation on a plot using relative coordinates. The 'relPos' argument takes a numeric vector of length two for x and y positioning. Other parameters control the legend's appearance. ```r # change pos annoLegend(object = p, relPos = c(0.2,0.9), labels = paste('legend ',1:5), pch = 21, col = 'black', fill = useMyCol('paired',5), textSize = 15) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.