Skip to content

Commit 07f138e

Browse files
committed
Merge pull request #1133 from SeySayux/feature/stroke
Add stroke option to geom_point.
2 parents 60a9f26 + 5380ecd commit 07f138e

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ ggplot2 1.0.1.9000
110110
(e.g., gridlines) on top of data. Usually used with blank or transparent
111111
`panel.background`. (@noamross. #551)
112112

113+
* Add `stroke` aesthetic to `geom_point` controlling the stroke width of the
114+
border for shape types 21 - 25 (#1133, @SeySayux)
115+
113116
ggplot2 1.0.1
114117
----------------------------------------------------------------
115118

R/geom-boxplot.r

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#' @param outlier.colour colour for outlying points. Uses the default from geom_point().
2727
#' @param outlier.shape shape of outlying points. Uses the default from geom_point().
2828
#' @param outlier.size size of outlying points. Uses the default from geom_point().
29+
#' @param outlier.stroke stroke width of outlying points. Uses the default from geom_point().
2930
#' @param notch if \code{FALSE} (default) make a standard box plot. If
3031
#' \code{TRUE}, make a notched box plot. Notches are used to compare groups;
3132
#' if the notches of two boxes do not overlap, this is strong evidence that
@@ -109,19 +110,21 @@
109110
geom_boxplot <- function (mapping = NULL, data = NULL, stat = "boxplot",
110111
position = "dodge", outlier.colour = NULL,
111112
outlier.shape = NULL, outlier.size = NULL,
112-
notch = FALSE, notchwidth = .5, varwidth = FALSE,
113-
show_guide = NA,...) {
113+
outlier.stroke = 1, notch = FALSE, notchwidth = .5,
114+
varwidth = FALSE, show_guide = NA,...) {
114115

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

117118
outlier.colour <- outlier.colour %||% outlier_defaults$colour
118119
outlier.shape <- outlier.shape %||% outlier_defaults$shape
119120
outlier.size <- outlier.size %||% outlier_defaults$size
121+
outlier.stroke <- outlier.stroke %||% outlier_defaults$stroke
120122

121123
GeomBoxplot$new(mapping = mapping, data = data, stat = stat,
122124
position = position, outlier.colour = outlier.colour,
123-
outlier.shape = outlier.shape, outlier.size = outlier.size, notch = notch,
124-
notchwidth = notchwidth, varwidth = varwidth, show_guide = show_guide,...)
125+
outlier.shape = outlier.shape, outlier.size = outlier.size,
126+
outlier.stoke = outlier.stroke, notch = notch, notchwidth = notchwidth,
127+
varwidth = varwidth, show_guide = show_guide,...)
125128
}
126129

127130
GeomBoxplot <- proto(Geom, {
@@ -157,7 +160,7 @@ GeomBoxplot <- proto(Geom, {
157160
df
158161
}
159162

160-
draw <- function(., data, ..., fatten = 2, outlier.colour = NULL, outlier.shape = NULL, outlier.size = 2,
163+
draw <- function(., data, ..., fatten = 2, outlier.colour = NULL, outlier.shape = NULL, outlier.size = 2, outlier.stroke = 1,
161164
notch = FALSE, notchwidth = .5, varwidth = FALSE) {
162165
common <- data.frame(
163166
colour = data$colour,
@@ -195,6 +198,7 @@ GeomBoxplot <- proto(Geom, {
195198
colour = outlier.colour %||% data$colour[1],
196199
shape = outlier.shape %||% data$shape[1],
197200
size = outlier.size %||% data$size[1],
201+
stroke = outlier.stroke %||% data$stroke[1],
198202
fill = NA,
199203
alpha = NA,
200204
stringsAsFactors = FALSE)

R/geom-point-.r

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#' d + geom_point(alpha = 1/20)
8383
#' d + geom_point(alpha = 1/100)
8484
#'
85+
#' # Using shapes with a border
86+
#' p <- ggplot(mtcars, aes(wt, mpg))
87+
#' p + geom_point(shape=21, size=5, colour='black', fill='white', stroke=4)
88+
#'
8589
#' # You can create interesting shapes by layering multiple points of
8690
#' # different sizes
8791
#' p <- ggplot(mtcars, aes(mpg, wt))
@@ -125,7 +129,7 @@ GeomPoint <- proto(Geom, {
125129

126130
with(coord_transform(coordinates, data, scales),
127131
ggname(.$my_name(), pointsGrob(x, y, size=unit(size, "mm"), pch=shape,
128-
gp=gpar(col=alpha(colour, alpha), fill = alpha(fill, alpha), fontsize = size * .pt)))
132+
gp=gpar(col=alpha(colour, alpha), fill = alpha(fill, alpha), lwd = stroke, fontsize = size * .pt)))
129133
)
130134
}
131135

@@ -137,13 +141,14 @@ GeomPoint <- proto(Geom, {
137141
gp=gpar(
138142
col=alpha(colour, alpha),
139143
fill=alpha(fill, alpha),
140-
fontsize = size * .pt)
144+
lwd=stroke,
145+
fontsize = size * .pt),
141146
)
142147
)
143148
}
144149

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

149154
})

R/geom-pointrange.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GeomPointrange <- proto(Geom, {
2121
objname <- "pointrange"
2222

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

man/geom_boxplot.Rd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
\usage{
77
geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot",
88
position = "dodge", outlier.colour = NULL, outlier.shape = NULL,
9-
outlier.size = NULL, notch = FALSE, notchwidth = 0.5,
10-
varwidth = FALSE, show_guide = NA, ...)
9+
outlier.size = NULL, outlier.stroke = 1, notch = FALSE,
10+
notchwidth = 0.5, varwidth = FALSE, show_guide = NA, ...)
1111
}
1212
\arguments{
1313
\item{mapping}{The aesthetic mapping, usually constructed with
@@ -29,6 +29,8 @@ a call to a position adjustment function.}
2929

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

32+
\item{outlier.stroke}{stroke width of outlying points. Uses the default from geom_point().}
33+
3234
\item{notch}{if \code{FALSE} (default) make a standard box plot. If
3335
\code{TRUE}, make a notched box plot. Notches are used to compare groups;
3436
if the notches of two boxes do not overlap, this is strong evidence that

man/geom_point.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ d + geom_point(alpha = 1/10)
9595
d + geom_point(alpha = 1/20)
9696
d + geom_point(alpha = 1/100)
9797

98+
# Using shapes with a border
99+
p <- ggplot(mtcars, aes(wt, mpg))
100+
p + geom_point(shape=21, size=5, colour='black', fill='white', stroke=4)
101+
98102
# You can create interesting shapes by layering multiple points of
99103
# different sizes
100104
p <- ggplot(mtcars, aes(mpg, wt))

0 commit comments

Comments
 (0)