Package 'ggnuplot'

Title: Make 'ggplot2' Look Like 'gnuplot'
Description: Provides a theme, a discrete color palette, and continuous scales to make 'ggplot2' look like 'gnuplot'. This may be helpful if you use both 'ggplot2' and 'gnuplot' in one project.
Authors: Hannes Riebl [aut, cre]
Maintainer: Hannes Riebl <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-02-11 03:11:05 UTC
Source: https://github.com/hriebl/ggnuplot

Help Index


The gnuplot color palette for discrete data, ported to ggplot2

Description

These functions provide gnuplot's default color palette. Use scale_color_gnuplot() and scale_fill_gnuplot() with ggplot2, and gnupalette() or the vector gnucolors otherwise.

Usage

scale_color_gnuplot(..., na.value = "gray50", aesthetics = "color")
scale_fill_gnuplot(..., na.value = "gray50", aesthetics = "fill")
gnupalette(n)

Arguments

...

Arguments passed on to discrete_scale

palette

A palette function that when called with a single integer argument (the number of levels in the scale) returns the values that they should take (e.g., scales::hue_pal()).

breaks

One of:

  • NULL for no breaks

  • waiver() for the default breaks (the scale limits)

  • A character vector of breaks

  • A function that takes the limits as input and returns breaks as output

limits

A character vector that defines possible values of the scale and their order.

drop

Should unused factor levels be omitted from the scale? The default, TRUE, uses the levels that appear in the data; FALSE uses all the levels in the factor.

na.translate

Unlike continuous scales, discrete scales can easily show missing values, and do so by default. If you want to remove missing values from a discrete scale, specify na.translate = FALSE.

scale_name

The name of the scale that should be used for error messages associated with this scale.

name

The name of the scale. Used as the axis or legend title. If waiver(), the default, the name of the scale is taken from the first mapping used for that aesthetic. If NULL, the legend title will be omitted.

labels

One of:

  • NULL for no labels

  • waiver() for the default labels computed by the transformation object

  • A character vector giving labels (must be same length as breaks)

  • A function that takes the breaks as input and returns labels as output

expand

For position scales, a vector of range expansion constants used to add some padding around the data to ensure that they are placed some distance away from the axes. Use the convenience function expansion() to generate the values for the expand argument. The defaults are to expand the scale by 5% on each side for continuous variables, and by 0.6 units on each side for discrete variables.

guide

A function used to create a guide or its name. See guides() for more information.

position

For position scales, The position of the axis. left or right for y axes, top or bottom for x axes.

super

The super class to use for the constructed scale

na.value

Colour to use for missing values

aesthetics

Character string or vector of character strings listing the name(s) of the aesthetic(s) that this scale works with. This can be useful, for example, to apply colour settings to the colour and fill aesthetics at the same time, via aesthetics = c("colour", "fill").

n

The number of colors to return

Examples

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point() +
  scale_color_gnuplot() +
  scale_x_gnuplot() +
  scale_y_gnuplot() +
  theme_gnuplot()

gnupalette(3)
gnucolors[1:3]

gnuplot-like (continuous) axes for ggplot2

Description

These functions set up gnuplot-like secondary axes. They also try to choose pretty breaks/ticks for continuous data. Your mileage with the breaks/ticks may vary, so be sure to try different settings.

Usage

scale_x_gnuplot(breaks = gnubreaks(), sec.axis = gnuaxis(), ...)
scale_y_gnuplot(breaks = gnubreaks(), sec.axis = gnuaxis(), ...)
gnubreaks(n = 5, padding = 0.1)

Arguments

breaks

One of:

  • NULL for no breaks

  • waiver() for the default breaks computed by the transformation object

  • A numeric vector of positions

  • A function that takes the limits as input and returns breaks as output (e.g., a function returned by scales::extended_breaks())

sec.axis

sec_axis() is used to specify a secondary axis.

...

Other arguments passed on to ⁠scale_(x|y)_continuous()⁠

n

The number of breaks/ticks to return

padding

The amount of space between the outermost breaks/ticks and the axis limits relative to the axis range. A number between 0 and 0.5.

See Also

The labeling package for alternative break/tick functions, and ggplot2::dup_axis(), for which gnuaxis() is an alias

Examples

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point() +
  scale_color_gnuplot() +
  scale_x_gnuplot() +
  scale_y_gnuplot() +
  theme_gnuplot()

gnuplot theme for ggplot2

Description

This theme makes ggplot2 look like gnuplot. It is based on ggplot2::theme_linedraw() and has inward ticks.

Usage

theme_gnuplot(
  base_size = 11,
  base_family = "",
  base_line_size = base_size/22,
  base_rect_size = base_size/22
)

Arguments

base_size

base font size

base_family

base font family

base_line_size

base size for line elements

base_rect_size

base size for rect elements

See Also

The default ggplot2 themes and ggplot2::theme()

Examples

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point() +
  scale_color_gnuplot() +
  scale_x_gnuplot() +
  scale_y_gnuplot() +
  theme_gnuplot()