ggplot2.scatterplot: Easy scatterplot plot using ggplot2

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/ggplot2.scatterplot.R

Description

Draw easily a scatter plot using ggplot2 package

Usage

1
2
3
4
5
6
7
ggplot2.scatterplot(data, xName, yName, groupName = NULL,
  addRegLine = FALSE, regLineColor = "blue", regLineSize = 0.5,
  smoothingMethod = c("lm", "glm", "gam", "loess", "rlm"),
  addConfidenceInterval = FALSE, confidenceLevel = 0.95,
  confidenceIntervalFill = "#C7C7C7", setColorByGroupName = TRUE,
  setShapeByGroupName = FALSE, groupColors = NULL, brewerPalette = NULL,
  ...)

Arguments

data

data.frame or a numeric vector. Columns are variables and rows are observations.

xName

The name of column containing x variable (i.e groups).

yName

The name of column containing y variable.

groupName

The name of column containing group variable. This variable is used to color plot according to the group.

addRegLine

If TRUE, regression line is added. Default value is FALSE.

regLineColor

Color of regression line. Default value is blue.

regLineSize

Weight of regression line. Default value is 0.5.

smoothingMethod

Smoothing method (function) to use, eg. lm, glm, gam, loess, rlm. For datasets with n < 1000 default is loess. For datasets with 1000 or more observations defaults to gam. lm for linear smooths, glm for generalised linear smooths, loess for local smooths, gam fits a generalized additive model.

addConfidenceInterval

Display confidence interval around smooth? (FALSE by default).

confidenceLevel

Level controling confidence region. Default is 95%

confidenceIntervalFill

Fill color of confidence intervall

setColorByGroupName

If TRUE, points are colored according the groups. Default value is TRUE.

setShapeByGroupName

If TRUE, point shapes are different according to the group. Default value is FALSE.

groupColors

Color of groups. groupColors should have the same length as groups.

brewerPalette

This can be also used to indicate group colors. In this case the parameter groupColors should be NULL. e.g: brewerPalette="Paired".

...

Other parameters passed on to ggplot2.customize custom function or to geom_smooth and to geom_point functions from ggplot2 package.

Value

a ggplot

Author(s)

Alboukadel Kassambara <alboukadel.kassambara@gmail.com>

References

http://www.sthda.com

See Also

ggplot2.dotplot, ggplot2.violinplot, ggplot2.stripchart, ggplot2.boxplot, ggplot2.histogram, ggplot2.lineplot, ggplot2.barplot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
df <- mtcars
ggplot2.scatterplot(data=df, xName='wt',yName='mpg', size=3,
                mainTitle="Plot of miles per gallon \n according to the weight",
                xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon")

#Or use this
plot<-ggplot2.scatterplot(data=df, xName='wt',yName='mpg', size=3)
plot<-ggplot2.customize(plot, mainTitle="Plot of miles per gallon \n according to the weight",
                        xtitle="Weight (lb/1000)", ytitle="Miles/(US) gallon")
print(plot)

kassambara/easyGgplot2 documentation built on May 20, 2019, 7:39 a.m.