1

I would like to increase border thickness of the violin plot in R. I tried to use lwd = x, but it makes it extremely thick no matter what number I replace x with. To be clear I want the border of the actual violins to be thicker.

Example df:

variable value
group1    26
group1    36
group1    26
group1    26
group1    27
group1    27
group2   100
group2   95
group2   120
group2   135
group2   88
group2   102

I am using the following code to plot the graph:

ggplot(df, aes(x = variable, y = value)) + 
  geom_violin(aes(fill = variable)) + 
  stat_summary(fun.y=median, geom="point") + 
  scale_fill_manual(values = c("blue", "green")) + 
  scale_y_continuous(trans = "log2") + 
  ylab("Quantity") + 
  scale_x_discrete(labels = c("group1", "group2")) + 
  theme(legend.position = "none")

I used lwd as follows: + geom_violin(aes(fill = variable, lwd = 1)) but any number I replace makes the border extremely thick. I just want it slightly thicker.

morgan121
  • 2,213
  • 1
  • 15
  • 33
sf1
  • 25
  • 1
  • 6
  • 8
    Try `geom_violin(aes(fill = variable), size = 1.25)` – Mako212 Nov 12 '19 at 22:00
  • 1
    Same thing happens, border becomes extremely thick – sf1 Nov 13 '19 at 16:03
  • 2
    Sometimes your graphics device can distort what the plot actually looks like. Try using `ggsave()` to save an image and see if you still have the same issue. – Mako212 Nov 13 '19 at 17:15
  • Works! Thank you! I was making the mistake of adding the argument in the brackets with the fill = variable. – sf1 Nov 14 '19 at 15:16

0 Answers0