Learn R Programming

ggwordcloud (version 0.2.0)

geom_text_wordcloud: wordcloud text geom

Description

geom_text_wordcloud adds text to the plot using a variation of the wordcloud2.js algorithm. The texts are layered around a spiral centered on the original position. This geom is based on geom_text_repel which in turn is based on geom_text. See the documentation for those functions for more details.

Usage

geom_text_wordcloud(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", ..., parse = FALSE, nudge_x = 0,
  nudge_y = 0, eccentricity = 0.65, rstep = 0.01, tstep = 0.02,
  grid_size = 4, max_grid_size = 128, grid_margin = 1, xlim = c(NA,
  NA), ylim = c(NA, NA), seed = NA, rm_outside = FALSE,
  na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE)

Arguments

mapping

Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), is combined with the default mapping at the top level of the plot. You only need to supply mapping if there isn't a mapping defined for the plot. Note that if not specified both x and y are set to 0.5, i.e. the middle of the default panel.

data

A data frame. If specified, overrides the default data frame defined at the top level of the plot.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

...

other arguments passed on to layer. There are three types of arguments you can use here:

  • Aesthetics: to set an aesthetic to a fixed value, like colour = "red" or size = 3.

  • Other arguments to the layer, for example you override the default stat associated with the layer.

  • Other arguments passed on to the stat.

parse

If TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath

nudge_x, nudge_y

Horizontal and vertical adjustments to nudge the starting position of each text label.

eccentricity

eccentricity of the spiral. Default to .65

rstep

relative wordclould spiral radius increment after one full rotation. Default to .01.

tstep

wordclould spiral angle increment at each step. Default to .02.

grid_size

grid size used when creating the text bounding boxes. Default to 4

max_grid_size

maximum size of the bounding boxes. Default to 128

grid_margin

safety margin around the texts. Default to 1.

xlim, ylim

Limits for the x and y axes. Text labels will be constrained to these limits. By default, text labels are constrained to the entire plot area.

seed

Random seed passed to set.seed. Defaults to NA, which means that set.seed will not be called.

rm_outside

Remove the texts that could not be fitted. Default to FALSE

na.rm

Remove missing values if TRUE

show.legend

is set by default to FALSE

inherit.aes

Inherits aesthetics if TRUE

Value

a ggplot

Examples

Run this code
# NOT RUN {
set.seed(42)
dat <- mtcars
dat$name <- row.names(mtcars)
dat$size <- dat$mpg
dat$size[1] <- 300
ggplot(data = dat, aes(size = size, label = name)) + geom_text_wordcloud() +
  theme_minimal()
dat$angle <- (-90+180*runif(nrow(dat)))*(runif(nrow(dat)>.6))
ggplot(data = dat, aes(size = size, label = name, angle = angle)) +
 geom_text_wordcloud() + theme_minimal()
# }

Run the code above in your browser using DataLab