-
Notifications
You must be signed in to change notification settings - Fork 2k
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
geom_point(): when stroke=NA, cannot change size of the point #4624
Comments
Thanks, confirmed. Here's another version of the reprex. Curious... library(ggplot2)
df = data.frame(x = rnorm(100), y = rnorm(100))
f <- function(stroke) {
ggplot(df, aes(x, y)) +
geom_point(shape = 21, stroke = stroke, colour = "red", fill = "black", size = 50) +
ggtitle(paste("stroke:", rlang::as_label(stroke)))
}
patchwork::wrap_plots(f(1), f(NA)) Created on 2021-09-20 by the reprex package (v2.0.1) |
I think it's this line: Line 133 in 759c63c
The library(ggplot2)
size <- 20
stroke <- 0
size * .pt + stroke * .stroke / 2
#> [1] 56.90551
stroke <- NA
size * .pt + stroke * .stroke / 2
#> [1] NA Created on 2021-09-20 by the reprex package (v2.0.0) |
The reason why I set library(ggplot2)
df = data.frame(x=rnorm(100), y=rnorm(100))
ggplot2::ggplot(df, aes(x, y)) + geom_point(shape=21, stroke=0, fill="orange", color="blue", size=3) Created on 2021-09-20 by the reprex package (v2.0.1) |
Ah, apparently graphics devices interpret 0 as "smallest possible visible line thickness". You can always set the color to transparent though, to get rid of the stroke entirely. library(ggplot2)
df <- data.frame(
x=rnorm(100), y=rnorm(100)
)
ggplot(df, aes(x, y)) +
geom_point(
shape=21, stroke=0, fill="orange",
color="transparent", size=3
) Created on 2021-09-20 by the reprex package (v2.0.0) |
Thanks. So, I guess the line should be something like stroke <- coords$stroke
stroke[is.na(stroke)] <- 0
...
fontsize = coords$size * .pt + stroke * .stroke / 2, |
Not sure entirely. That would still leave the thin outline, but getting rid of it is kind of tricky (we can't just set |
We just need to ignore stroke in the size calculations if it is NA stroke_size <- coords$stroke
stroke_size[is.na(stroke_size)] <- 0
...
fontsize = coords$size * .pt + stroke_size * .stroke / 2,
lwd = coords$stroke * .stroke / 2 Or am I missing something? (and an aside, yes - the specs for graphics devices is that a line width of 0 should equate to the thinnest possible line, for whatever reason someone thought that was a good idea) |
I'm trying to generate a plot with points with no border displayed, just fill and to be able to change their size. However, once
stroke=NA
, I cannot change the size of the points.Created on 2021-09-20 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: