Learn R Programming

henna (version 0.7.5)

densityPlot: Create density plot

Description

This function creates a density plot.

Usage

densityPlot(
  df,
  title = NULL,
  colorScheme = c("cloudy", "cake", "grapes", "lava", "oasis", "orichalc", "sea", "sky",
    "custom"),
  useSchemeDefaults = TRUE,
  drawNN = TRUE,
  drawScores = FALSE,
  xLab = NULL,
  yLab = NULL,
  legendTitle = "Density",
  palette = NULL,
  segColor = "black",
  pointSize = 1,
  pointColor = "red",
  segType = c("dashed", "solid", "dotted", "dotdash", "longdash", "twodash"),
  segWidth = 0.4,
  nGridPoints = 300,
  expandPerc = 20,
  labelType = c("free", "boxed"),
  labelSize = 3,
  labelColor = "black",
  labelRepulsion = 1,
  labelPull = 1,
  maxOverlaps = 10,
  labelPadding = 0,
  boxPadding = 0,
  labelSegWidth = 0.4,
  legendPos = c("right", "none"),
  legendTextSize = 10,
  legendTitleSize = 10,
  axisTextSize = 12,
  axisTitleSize = 12,
  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. Choose between 'cake', 'cloudy', 'grapes', 'lava', oasis', 'orichalc', 'sea', 'sky' and 'custom'. Default is 'cloudy'.

useSchemeDefaults

Whether to use the default segColor, pointColor and labelColor values 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.

xLab

x axis label.

yLab

y axis label.

legendTitle

Legend title.

palette

A character vector of colors. 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. 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.

nGridPoints

Number of grid points in each direction.

expandPerc

Percentage by which the grid will be expanded.

labelType

Whether to draw a box around labels (option 'boxed') or not (option 'free'). Default is 'free'.

labelSize

Label size.

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 number of allowed overlaps.

labelPadding

Amount of padding around label.

boxPadding

Amount of padding around box.

labelSegWidth

Thickness of segment connecting label to point.

legendPos

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

legendTextSize

Legend text size.

legendTitleSize

Legend title size.

axisTextSize

Axis text size.

axisTitleSize

Axis title size.

verbose

Whether output should be verbose.

...

Additional 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