jhp
1
I have a simple plot:
library(ggplot2)
ggplot(mtcars, aes(mpg, disp, fill = "fill")) +
geom_violin(aes(linetype = "pattern"),
key_glyph = draw_key_path)
![](https://forum.posit.co/uploads/default/original/3X/7/8/789a386d87d9596e596f61a1d8079cc9af352a49.png)
Created on 2021-11-08 by the reprex package (v0.3.0)
How can I change the legend to show the fill
as a square, but the linetype
pattern as just a line instead of a square?
Rsky
2
library(tidyverse)
mtcars %>%
mutate(fill="1") %>%
ggplot(aes(x=mpg, y=disp, fill = fill)) +
geom_violin(aes(linetype = "pattern"),
key_glyph = draw_key_path)+
guides(fill = guide_legend(
override.aes = list(linetype = 0)))+
theme(legend.key =element_rect(fill=c("salmon")))+
scale_fill_manual(name = "fill legend",
values = 'salmon',
labels = c('fill here'))
![image](https://forum.posit.co/uploads/default/original/3X/e/3/e3d5a5878886b4b756ac0332706b1134157f5d19.png)
I could not find a way to separate the legend.key.
If anyone else knows how to do this, please let me know.
1 Like
system
Closed
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.