Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set default size for `geom_line` in ggplot?

I want to change the default thickness of geom_line using the size aesthetic. This question has already been answered here but the solution – to set the default value using update_geom_defaults does not work for me.

Here’s a minimum reproducible example:

library(tidyverse)

update_geom_defaults("line", list(size = 2))

data(ChickWeight)

ChickWeight %>%
  filter(Chick %in% c("1", "2", "3")) %>%
  ggplot(aes(x = Time, y = weight, colour = Chick)) +
  geom_line()

The result I get is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Line plot - size is still 1

update_geom_defaults does work for changing e.g. the default colour. Any idea what’s going on here and how to successfully change the default size?

>Solution :

You could use linewidth to change the thickness like this:

library(tidyverse)

update_geom_defaults("line", list(linewidth = 2))

data(ChickWeight)

ChickWeight %>%
  filter(Chick %in% c("1", "2", "3")) %>%
  ggplot(aes(x = Time, y = weight, colour = Chick)) +
  geom_line()

Created on 2023-02-02 with reprex v2.0.2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading