Examples for 'GGally::ggally_cross'


Plots the number of observations

Aliases: ggally_cross

Keywords: hplot

### ** Examples

# Small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive

data(tips, package = "reshape")
p_(ggally_cross(tips, mapping = aes(x = smoker, y = sex)))
plot of chunk example-GGally-ggally_cross-1
p_(ggally_cross(tips, mapping = aes(x = day, y = time)))
plot of chunk example-GGally-ggally_cross-1
# Custom max size
p_(ggally_cross(tips, mapping = aes(x = smoker, y = sex)) +
  scale_size_area(max_size = 40))
Scale for 'size' is already present. Adding another scale for 'size', which
will replace the existing scale.
plot of chunk example-GGally-ggally_cross-1
# Custom fill
p_(ggally_cross(tips, mapping = aes(x = smoker, y = sex), fill = "red"))
plot of chunk example-GGally-ggally_cross-1
# Custom shape
p_(ggally_cross(tips, mapping = aes(x = smoker, y = sex), shape = 21))
plot of chunk example-GGally-ggally_cross-1
# Fill squares according to standardized residuals
d <- as.data.frame(Titanic)
p_(ggally_cross(
  d,
  mapping = aes(x = Class, y = Survived, weight = Freq, fill = after_stat(std.resid))
) +
  scale_fill_steps2(breaks = c(-3, -2, 2, 3), show.limits = TRUE))
plot of chunk example-GGally-ggally_cross-1
# Add labels
p_(ggally_cross(
  tips,
  mapping = aes(
    x = smoker, y = sex, colour = smoker,
    label = scales::percent(after_stat(prop))
  )
))
plot of chunk example-GGally-ggally_cross-1
# Customize labels' appearance and same size for all squares
p_(ggally_cross(
  tips,
  mapping = aes(
    x = smoker, y = sex,
    size = NULL, # do not map size to a variable
    label = scales::percent(after_stat(prop))
  ),
  size = 40, # fix value for points size
  fill = "darkblue",
  geom_text_args = list(colour = "white", fontface = "bold", size = 6)
))
plot of chunk example-GGally-ggally_cross-1

[Package GGally version 2.1.2 Index]