You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When xend = x and yend = y, the plot that I see in rstudio shows a "point" for 0-length segments plotted by geom_segment. This is desirable to my use-case:
However, I noticed in shiny, length 0 segments are not shown at all:
I'm using RStudio Server 2024.12.1 Build 563.
I can see if exported to png there is also no length 0 segments being displayed.
I see some potentially relevant issues but none that describe this inconsistency: #5140#3894
I'm not sure what the intended behaviour is, my use-case is to prefer a representation of 0-length segments as points, but I can understand why that might not be the intended geom_segment behaviour. For example, I can get around this by using geom_point for those cases. I think that the plot in rstudio viewer should be the same as shiny output, exported through ggsave, etc. though.
library(ggplot2)
library(dplyr)
library(tibble)
library(shiny)
library(bslib)
ggplot2::theme_set(theme_bw())
df <- tibble(
x = c(1, 1, 1),
xend = c(2, 5, 1),
y = c('len1', 'len4', 'len0')
)
plot_example <- df |>
ggplot(aes(x = x, y = y)) +
geom_segment(aes(xend = xend, yend = y), linewidth = 7, lineend = 'round')
# see length 0 is displayed as a "point"
plot_example
# length 0 is not displayed at all
ui <- page_sidebar(
plotOutput('plot')
)
shinyApp(
ui,
function(input, output) {
output$plot <- renderPlot({
plot_example
})
}
)
# export png does not show length 0 segments either
ggsave('plot_example.png', plot_example)
The text was updated successfully, but these errors were encountered:
wvictor14
changed the title
Length 0 geom_segments inconsistent depending on output
Length 0 geom_segment representation depends on viewing through rstudio or other (shiny, exporting to file)
May 5, 2025
Thanks for the report! I agree that this can be frustrating, but the display of 0-length segments is at the discretion of the graphics devices, over which ggplot2 has little control. If you want consistency, then perhaps lineend = "butt" is a better choice than the round line ends.
When
xend
=x
andyend
=y
, the plot that I see in rstudio shows a "point" for 0-length segments plotted bygeom_segment
. This is desirable to my use-case:However, I noticed in shiny, length 0 segments are not shown at all:
I'm using RStudio Server 2024.12.1 Build 563.
I can see if exported to png there is also no length 0 segments being displayed.
I see some potentially relevant issues but none that describe this inconsistency: #5140 #3894
I'm not sure what the intended behaviour is, my use-case is to prefer a representation of 0-length segments as points, but I can understand why that might not be the intended geom_segment behaviour. For example, I can get around this by using
geom_point
for those cases. I think that the plot in rstudio viewer should be the same as shiny output, exported through ggsave, etc. though.The text was updated successfully, but these errors were encountered: