ggplot_pretty: Customize appearnace of ggplot's geom_point()

Description Usage Arguments Examples

View source: R/ggplot_pretty.R

Description

Control many of the common features of a plot all in one, intuitive function!

Usage

1
ggplot_pretty(df, x, y, title, titlesize, colorby, bkg_color, panel_color, x_axis_label, y_axis_label, font, legend_title, legend_position)

Arguments

df

The data.frame that contains the data to plot

x

x axis variable

y

y axis variable

title

Character vector representing title of the plot

titlesize

set size of title

colorby

must be a variable within dataset to color scatter points by

bkg_color

set color of area outside of plot

panel_color

set color of plot area

x_axis_label

character vector of text that is the x axis label

y_axis_label

character vector of text that is the y axis label

font

character vector of font to be used on plot. Default choices are "serif", "sans", or "mono".

legend_title

character vector of text to be used as legend title

legend_position

character vector that is the posiiton of the legend

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
df = mtcars

x = df$hp
y = df$disp

title = "Engine Displacement vs Horsepower"
titlesize = 20
colorby = factor(df$cyl)
bkg_color = "lightblue"
panel_color = "bisque"
x_axis_label = "Engine Horsepower"
y_axis_label = "Engine Displacement"
font = "serif"
legend_title = "Engine Cylinders"
legend_position = "bottom"

ggplot_pretty(df, x, y, title, titlesize, colorby, bkg_color,
                          panel_color, x_axis_label, y_axis_label, font,
                          legend_title, legend_position)

## The function is currently defined as
function (df, x, y, title, titlesize, colorby, bkg_color, panel_color,
    x_axis_label, y_axis_label, font, legend_title, legend_position)
{
    require(ggplot2)
    pp <- ggplot(df, aes(x = x, y = y, color = colorby)) + geom_point() +
        labs(title = title, x = x_axis_label, y = y_axis_label) +
        theme(plot.title = element_text(size = titlesize), plot.background = element_rect(fill = bkg_color),
            panel.background = element_rect(fill = panel_color),
            text = element_text(family = font), legend.position = legend_position)
    pp + scale_colour_discrete(name = legend_title)
  }

jtuttle7/LearnFunctions documentation built on May 25, 2019, 6:25 p.m.