Skip to content

Add stroke option to geom_point. #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ ggplot2 1.0.1.9000
(e.g., gridlines) on top of data. Usually used with blank or transparent
`panel.background`. (@noamross. #551)

* Add `stroke` aesthetic to `geom_point` controlling the stroke width of the
border for shape types 21 - 25 (#1133, @SeySayux)

ggplot2 1.0.1
----------------------------------------------------------------

Expand Down
14 changes: 9 additions & 5 deletions R/geom-boxplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' @param outlier.colour colour for outlying points. Uses the default from geom_point().
#' @param outlier.shape shape of outlying points. Uses the default from geom_point().
#' @param outlier.size size of outlying points. Uses the default from geom_point().
#' @param outlier.stroke stroke width of outlying points. Uses the default from geom_point().
#' @param notch if \code{FALSE} (default) make a standard box plot. If
#' \code{TRUE}, make a notched box plot. Notches are used to compare groups;
#' if the notches of two boxes do not overlap, this is strong evidence that
Expand Down Expand Up @@ -109,19 +110,21 @@
geom_boxplot <- function (mapping = NULL, data = NULL, stat = "boxplot",
position = "dodge", outlier.colour = NULL,
outlier.shape = NULL, outlier.size = NULL,
notch = FALSE, notchwidth = .5, varwidth = FALSE,
show_guide = NA,...) {
outlier.stroke = 1, notch = FALSE, notchwidth = .5,
varwidth = FALSE, show_guide = NA,...) {

outlier_defaults <- Geom$find('point')$default_aes()

outlier.colour <- outlier.colour %||% outlier_defaults$colour
outlier.shape <- outlier.shape %||% outlier_defaults$shape
outlier.size <- outlier.size %||% outlier_defaults$size
outlier.stroke <- outlier.stroke %||% outlier_defaults$stroke

GeomBoxplot$new(mapping = mapping, data = data, stat = stat,
position = position, outlier.colour = outlier.colour,
outlier.shape = outlier.shape, outlier.size = outlier.size, notch = notch,
notchwidth = notchwidth, varwidth = varwidth, show_guide = show_guide,...)
outlier.shape = outlier.shape, outlier.size = outlier.size,
outlier.stoke = outlier.stroke, notch = notch, notchwidth = notchwidth,
varwidth = varwidth, show_guide = show_guide,...)
}

GeomBoxplot <- proto(Geom, {
Expand Down Expand Up @@ -157,7 +160,7 @@ GeomBoxplot <- proto(Geom, {
df
}

draw <- function(., data, ..., fatten = 2, outlier.colour = NULL, outlier.shape = NULL, outlier.size = 2,
draw <- function(., data, ..., fatten = 2, outlier.colour = NULL, outlier.shape = NULL, outlier.size = 2, outlier.stroke = 1,
notch = FALSE, notchwidth = .5, varwidth = FALSE) {
common <- data.frame(
colour = data$colour,
Expand Down Expand Up @@ -195,6 +198,7 @@ GeomBoxplot <- proto(Geom, {
colour = outlier.colour %||% data$colour[1],
shape = outlier.shape %||% data$shape[1],
size = outlier.size %||% data$size[1],
stroke = outlier.stroke %||% data$stroke[1],
fill = NA,
alpha = NA,
stringsAsFactors = FALSE)
Expand Down
11 changes: 8 additions & 3 deletions R/geom-point-.r
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
#' d + geom_point(alpha = 1/20)
#' d + geom_point(alpha = 1/100)
#'
#' # Using shapes with a border
#' p <- ggplot(mtcars, aes(wt, mpg))
#' p + geom_point(shape=21, size=5, colour='black', fill='white', stroke=4)
#'
#' # You can create interesting shapes by layering multiple points of
#' # different sizes
#' p <- ggplot(mtcars, aes(mpg, wt))
Expand Down Expand Up @@ -125,7 +129,7 @@ GeomPoint <- proto(Geom, {

with(coord_transform(coordinates, data, scales),
ggname(.$my_name(), pointsGrob(x, y, size=unit(size, "mm"), pch=shape,
gp=gpar(col=alpha(colour, alpha), fill = alpha(fill, alpha), fontsize = size * .pt)))
gp=gpar(col=alpha(colour, alpha), fill = alpha(fill, alpha), lwd = stroke, fontsize = size * .pt)))
)
}

Expand All @@ -137,13 +141,14 @@ GeomPoint <- proto(Geom, {
gp=gpar(
col=alpha(colour, alpha),
fill=alpha(fill, alpha),
fontsize = size * .pt)
lwd=stroke,
fontsize = size * .pt),
)
)
}

default_stat <- function(.) StatIdentity
required_aes <- c("x", "y")
default_aes <- function(.) aes(shape=16, colour="black", size=2, fill = NA, alpha = NA)
default_aes <- function(.) aes(shape=16, colour="black", size=2, fill = NA, alpha = NA, stroke = 1)

})
2 changes: 1 addition & 1 deletion R/geom-pointrange.r
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GeomPointrange <- proto(Geom, {
objname <- "pointrange"

default_stat <- function(.) StatIdentity
default_aes <- function(.) aes(colour = "black", size=0.5, linetype=1, shape=16, fill=NA, alpha = NA)
default_aes <- function(.) aes(colour = "black", size=0.5, linetype=1, shape=16, fill=NA, alpha = NA, stroke = 1)
guide_geom <- function(.) "pointrange"
required_aes <- c("x", "y", "ymin", "ymax")

Expand Down
6 changes: 4 additions & 2 deletions man/geom_boxplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
\usage{
geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot",
position = "dodge", outlier.colour = NULL, outlier.shape = NULL,
outlier.size = NULL, notch = FALSE, notchwidth = 0.5,
varwidth = FALSE, show_guide = NA, ...)
outlier.size = NULL, outlier.stroke = 1, notch = FALSE,
notchwidth = 0.5, varwidth = FALSE, show_guide = NA, ...)
}
\arguments{
\item{mapping}{The aesthetic mapping, usually constructed with
Expand All @@ -29,6 +29,8 @@ a call to a position adjustment function.}

\item{outlier.size}{size of outlying points. Uses the default from geom_point().}

\item{outlier.stroke}{stroke width of outlying points. Uses the default from geom_point().}

\item{notch}{if \code{FALSE} (default) make a standard box plot. If
\code{TRUE}, make a notched box plot. Notches are used to compare groups;
if the notches of two boxes do not overlap, this is strong evidence that
Expand Down
4 changes: 4 additions & 0 deletions man/geom_point.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ d + geom_point(alpha = 1/10)
d + geom_point(alpha = 1/20)
d + geom_point(alpha = 1/100)

# Using shapes with a border
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(shape=21, size=5, colour='black', fill='white', stroke=4)

# You can create interesting shapes by layering multiple points of
# different sizes
p <- ggplot(mtcars, aes(mpg, wt))
Expand Down