Learn R Programming

henna (version 0.3.4)

densityPlot: Create density plot

Description

This function creates a density plot.

Usage

densityPlot(
  df,
  title = "Density plot",
  colorScheme = c("oasis", "sea", "lava", "custom"),
  useSchemeDefaults = FALSE,
  drawNN = TRUE,
  drawScores = FALSE,
  palette = NULL,
  segColor = "plum1",
  pointSize = 0.8,
  pointColor = "red",
  segType = c("dashed", "solid", "dotted", "dotdash", "longdash", "twodash"),
  segWidth = 0.4,
  legendPos = c("right", "none"),
  nGridPoints = 300,
  expandPerc = 20,
  labelSize = 2.5,
  labelColor = "black",
  labelRepulsion = 1,
  labelPull = 1,
  maxOverlaps = Inf,
  verbose = FALSE,
  ...
)

Value

An object of class gg.

Arguments

df

A data frame with at least two columns, representing the x and y coordinates of the points. A score column can also be provided as the third column. Nearest neighbor information can be provided in the last column as a character vector with elements selected from the rownames.

title

Plot title.

colorScheme

Color scheme.

useSchemeDefaults

Whether to use the default segColor, pointColor and labelColor for scheme. Ignored if colorScheme is set to 'custom'.

drawNN

Whether to draw segments linking each point to its nearest neighbor.

drawScores

Whether to render scores on the plot. If set to TRUE, the third column of the input data frame will be numeric and scores will be taken from there.

palette

Color palette. Used only if color scheme is set to 'custom'.

segColor

Nearest neighbor segment color. Ignored if drawNN is set to FALSE, or if useSchemeDefaults is TRUE and colorScheme is different from 'custom'.

pointSize

Point size.

pointColor

Point color. Ignored if useSchemeDefaults is TRUE and colorScheme is different from 'custom'.

segType

Nearest neighbor segment type. Must choose between 'solid', 'dashed', 'dotted','dotdash', 'longdash' and 'twodash'. Ignored if drawNN is set to FALSE.

segWidth

Nearest neighbor segment width. Ignored if drawNN is set to FALSE.

legendPos

Legend position. Choose between 'right' and 'none'.

nGridPoints

Number of grid points in each direction.

expandPerc

Percentage by which the grid will be expanded.

labelSize

Size of labels of strata elements.

labelColor

Label color. Ignored if useSchemeDefaults is TRUE and colorScheme is different from 'custom'.

labelRepulsion

Repulsion strength between labels.

labelPull

Attraction strength between a text label and its data point.

maxOverlaps

Maximum overlaps.

verbose

Whether output should be verbose.

...

Other arguments passed to centerTitle.

Examples

Run this code
x <- c(1, 2, 3, 4, 6, 7, 8, 10, 12, 11, 3, 6, 4, 1, 13, 13, 14, 18, 16)
y <- c(1, 3, 1, 4, 3, 2, 8, 2, 1, 11, 8, 8, 10, 14, 13, 11, 11, 12,15)
z <- round(runif(19, 75, 100), 2)
df <- data.frame(x, y, z)
rownames(df) <- paste0('p', rownames(df))
densityPlot(df)

Run the code above in your browser using DataLab