1

I created a swimmer plot using package swimplot and added response lines to the graph, but the legend symbols have borders that I cannot figure out how to remove.

swimmer_lines(
  df_lines = resp, id = "study_id", start = "response_start",
  end = "response_end", name_col = "response", size = 1
) +
  scale_color_manual(
    name = "Response",
    values = c("PD" = "red", "SD" = "grey", "PR" = "mediumpurple", "CR" = "violetred1"),
    breaks = c("PD", "SD", "PR", "CR")
  ) +
  guides(color = guide_legend(override.aes = list(fill = NA)))

How can I remove the "borders" on each of the legend symbols without removing the line/legend symbol itself?

stefan
  • 90,330
  • 6
  • 25
  • 51
Alex
  • 53
  • 4
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Include the necessary `library()` calls in your sample code. – MrFlick Jan 03 '23 at 20:22
  • 3
    Welcome to SO, Alex! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. (Please no images of data, see https://meta.stackoverflow.com/a/285557 (and https://xkcd.com/2116/).) – r2evans Jan 03 '23 at 20:22

1 Answers1

1

You didn't include the code for your base swimplot, but if you only want the lines in the legend, you could do:

library(swimplot)
library(ggplot2)

swimmer_plot(df = resp, id = "study_id", start = "response_start",
  end = "response_end", name_col = "response", size = 1, fill = NA,
  color = NA) + 
  swimmer_lines(resp, id = "study_id", start = "response_start",
                  end = "response_end", name_col = "response", size = 1) +
  scale_color_manual(name = "Response",
    values = c("PD" = "red", "SD" = "grey", "PR" = "mediumpurple",
               "CR" = "violetred1"),
    breaks = c("PD", "SD", "PR", "CR")) 

Created on 2023-01-03 with reprex v2.0.2


Data used

In the absence of a reproducible example, here is a data frame with the same characteristics as the OP's, inferred from the supplied code:

resp <- data.frame(study_id = c("A", "B", "C", "D"),
                   response_start = 1:4, response_end = 4:7,
                   response = c("PD", "SD", "PR", "CR"))
Allan Cameron
  • 147,086
  • 7
  • 49
  • 87