-
Notifications
You must be signed in to change notification settings - Fork 2.1k
geom_tile borders missing notch at top left corners #3037
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
Comments
Thanks, agreed. |
Just a comment in passing. Ignore if off topic. from https://github.com/tidyverse/ggplot2/blob/master/R/geom-tile.r the first few lines: #' which is precisely the problem with Can you achieve your goal with |
I don't think it matters. library(ggplot2)
df <- expand.grid(x = 1:3, y = 1:3)
width <- 0.7
height <- 0.7
df$xmin <- df$x - width / 2
df$xmax <- df$x + width / 2
df$ymin <- df$y - height / 2
df$ymax <- df$y + height / 2
ggplot(df) +
geom_rect(aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
fill = NA, colour = "red", size = 3) Created on 2018-12-16 by the reprex package (v0.2.1) |
The problem is that the rectangles gets converted to polygons in closed form (first point gets repeated in the end), whereas polygonGrob expect an open representation... should be fairly easy to fix here: Lines 75 to 80 in 9eae13b
Note that this line also need to be adapted Line 42 in 9eae13b
|
On that note I don't think it makes sense to add a lineend parameter to the geoms as they should be closed, while adding linejoin is sensible... @yutannihilation can you update #3050 to create the correct polygon spec and remove lineend? I'm pretty sure it will break some visual tests, but it'll be more correct |
Opps, I didn't notice... Thanks, it makes sense. I will update so. |
It's a weird bug... probably a leftover from when the other representation made sense... recall anything @hadley ? |
FYI it also seems to be inconsistent, I can't reproduce with the reprex provided df <- expand.grid(x = 1:3, y = 1:3)
library("ggplot2")
ggplot(df) +
geom_tile(aes(x = x, y = y),
fill = NA, colour = "red", size = 3, width = 0.7, height = 0.7) Created on 2019-01-15 by the reprex package (v0.2.1) |
In response to the original SO question, someone else commented that they couldn't reproduce the issue on macOS either. @karawoo are you running on macOS, too? |
Ah yes, I am |
Curious. Visual tests pass even on my Windows, so I guess this is a problem on Windows' graphic device? |
It seems we still need library("ggplot2")
ggplot(data.frame(x = 1)) +
geom_tile(aes(x, x),
fill = NA, colour = "red", size = 10,
width = 1, height = 1) +
coord_equal() Created on 2019-01-25 by the reprex package (v0.2.1) |
o_O - that does not make any sense at all... maybe this is a windows issue (assuming that you're on windows... what do you get if you run: grid::grid.rect(width = unit(.5, 'npc'), height = unit(0.5, 'npc'), gp = grid::gpar(lwd = 20, linejoin = 'mitre')) |
Oh... Here's the result. library(grid)
grid.rect(width = unit(.5, 'npc'), height = unit(0.5, 'npc'), gp = gpar(lwd = 20, linejoin = 'mitre')) Created on 2019-01-25 by the reprex package (v0.2.1) |
ok, that is not what I get (i.e. I get even corners all around) This is a grid bug (or even a windows device bug) - @pmur002 do you have any idea where this comes from..? |
Hmm, thanks. Sorry that I haven't noticed this is the problem on Windows earlier... |
I see it (only on Windows). This appears to be a bug (or at least a poor design choice) in graphapp (that underlies the Windows device). graphapp's rectangle drawing draws a polyline, so what we are seeing is a line being drawn from the top-left corner around the perimeter of the rectangle. So the rounded top-left corner is round because of the rounded line start and end. You can work around the problem by specifying "square" lineend for the rectangle (which you should not have to do) - is that a possibility ? Code below shows what I mean for the simple grid.rect() demonstration
|
Thanks!
I think it's possible, since we already specify Line 61 in 256b26a
|
Ah, though we can use
So, we have several choices:
|
@thomasp85 I think I found the reason why the polygons are in closed form... |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This is an issue that has been discussed over at Stackoverflow. The original problem can be found here. A minimal reprex is included below.
I have the following data frame:
I would like to plot it as a
geom_tile
usingggplot2
like so:which gives,
Notice that in the top left corner of each tile the border has a notch missing and that the corner doesn't dovetail nicely like the other corners. The outcome I expected was a square around each tile, perhaps something like this:
A solution offered here by Z. Lin in that Stackoverflow thread suggests that
linejoin
andlineend
forgeom_tile
are switched tomitre
andsquare
, respectively. Or, that they are at least offered as parameters in thegeom
so that the user can choose for themselves. Hopefully, this demonstrates my issue adequately, but please let me know if I can clarify any aspect.The text was updated successfully, but these errors were encountered: