Skip to content

Length 0 geom_segment representation depends on viewing through rstudio or other (shiny, exporting to file) #6446

Open
@wvictor14

Description

@wvictor14

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:

Image

However, I noticed in shiny, length 0 segments are not shown at all:

Image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions