How to set a default line size in a ggplot2 theme (ggtheme)?












0















I forked the ggthemes git repo to make my own custom theme. I've figured out how to do almost everything I need, but have one hang up.



I am specifically trying to set the default size for geom_line() in my ggtheme.



Where I'm at now, I have to do something like this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line(size = 1.75) +
theme_mycustomtheme()


When I would prefer to just have to do this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line() +
theme_mycustomtheme() # this would set the line size automatically


I have edited my mycustomtheme.R file like so:



theme(
# Elements in this first block aren't used directly, but are inherited
# by others
line = element_line(
color = "black", size = 1.75,
linetype = 1, lineend = "butt"
)


Note how the size is now set to 1.75. But it doesn't seem to make a difference when I call the theme in practice.



I would appreciate any pointers as to what I may be doing wrong. Thanks!










share|improve this question

























  • Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

    – iod
    Nov 21 '18 at 18:20











  • I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

    – 42-
    Nov 21 '18 at 18:22


















0















I forked the ggthemes git repo to make my own custom theme. I've figured out how to do almost everything I need, but have one hang up.



I am specifically trying to set the default size for geom_line() in my ggtheme.



Where I'm at now, I have to do something like this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line(size = 1.75) +
theme_mycustomtheme()


When I would prefer to just have to do this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line() +
theme_mycustomtheme() # this would set the line size automatically


I have edited my mycustomtheme.R file like so:



theme(
# Elements in this first block aren't used directly, but are inherited
# by others
line = element_line(
color = "black", size = 1.75,
linetype = 1, lineend = "butt"
)


Note how the size is now set to 1.75. But it doesn't seem to make a difference when I call the theme in practice.



I would appreciate any pointers as to what I may be doing wrong. Thanks!










share|improve this question

























  • Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

    – iod
    Nov 21 '18 at 18:20











  • I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

    – 42-
    Nov 21 '18 at 18:22
















0












0








0








I forked the ggthemes git repo to make my own custom theme. I've figured out how to do almost everything I need, but have one hang up.



I am specifically trying to set the default size for geom_line() in my ggtheme.



Where I'm at now, I have to do something like this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line(size = 1.75) +
theme_mycustomtheme()


When I would prefer to just have to do this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line() +
theme_mycustomtheme() # this would set the line size automatically


I have edited my mycustomtheme.R file like so:



theme(
# Elements in this first block aren't used directly, but are inherited
# by others
line = element_line(
color = "black", size = 1.75,
linetype = 1, lineend = "butt"
)


Note how the size is now set to 1.75. But it doesn't seem to make a difference when I call the theme in practice.



I would appreciate any pointers as to what I may be doing wrong. Thanks!










share|improve this question
















I forked the ggthemes git repo to make my own custom theme. I've figured out how to do almost everything I need, but have one hang up.



I am specifically trying to set the default size for geom_line() in my ggtheme.



Where I'm at now, I have to do something like this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line(size = 1.75) +
theme_mycustomtheme()


When I would prefer to just have to do this:



economics %>%
ggplot(aes(date, uempmed)) +
geom_line() +
theme_mycustomtheme() # this would set the line size automatically


I have edited my mycustomtheme.R file like so:



theme(
# Elements in this first block aren't used directly, but are inherited
# by others
line = element_line(
color = "black", size = 1.75,
linetype = 1, lineend = "butt"
)


Note how the size is now set to 1.75. But it doesn't seem to make a difference when I call the theme in practice.



I would appreciate any pointers as to what I may be doing wrong. Thanks!







r ggplot2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 22:43







Adhi R.

















asked Nov 21 '18 at 18:12









Adhi R.Adhi R.

355




355













  • Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

    – iod
    Nov 21 '18 at 18:20











  • I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

    – 42-
    Nov 21 '18 at 18:22





















  • Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

    – iod
    Nov 21 '18 at 18:20











  • I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

    – 42-
    Nov 21 '18 at 18:22



















Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

– iod
Nov 21 '18 at 18:20





Pretty sure theme doesn't control that - the "line" argument in theme controls the various other .line arguments within it, not lines created by geom_line()

– iod
Nov 21 '18 at 18:20













I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

– 42-
Nov 21 '18 at 18:22







I would think that one would need to have theme_mycustomtheme <- theme(...) in the .R file. Otherwise loading it wouldn't have any effect. And you may need to invoke ?theme_update to get more information.

– 42-
Nov 21 '18 at 18:22














1 Answer
1






active

oldest

votes


















2














themes don't affect lines in geoms, only lines in axes, gridlines, etc. But, you can change the default appearance of geoms using update_geom_defaults().



#specify geom to update, and list attibutes you want to change appearance of
update_geom_defaults("line", list(size = 1.75))

#now your graph will plot with the line size you defined as default
economics %>%
ggplot(aes(date, uempmed)) +
geom_line()


If you add update_geom_defaults("line", list(size = 1.75)) to the file where you store your custom theme, your geom defaults will also update when you source() your mycustomtheme.r file, and you'll get the linetype you want. Note that setting defaults this way only changes the exact geom specified (line), and does not affect line elements in other geoms (boxplot borders, error bars, etc.), so you will need to define geom defaults for each individual geom you plan to use.






share|improve this answer
























  • Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

    – Adhi R.
    Nov 21 '18 at 22:38













  • The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

    – jrnold
    Nov 22 '18 at 19:19













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418209%2fhow-to-set-a-default-line-size-in-a-ggplot2-theme-ggtheme%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














themes don't affect lines in geoms, only lines in axes, gridlines, etc. But, you can change the default appearance of geoms using update_geom_defaults().



#specify geom to update, and list attibutes you want to change appearance of
update_geom_defaults("line", list(size = 1.75))

#now your graph will plot with the line size you defined as default
economics %>%
ggplot(aes(date, uempmed)) +
geom_line()


If you add update_geom_defaults("line", list(size = 1.75)) to the file where you store your custom theme, your geom defaults will also update when you source() your mycustomtheme.r file, and you'll get the linetype you want. Note that setting defaults this way only changes the exact geom specified (line), and does not affect line elements in other geoms (boxplot borders, error bars, etc.), so you will need to define geom defaults for each individual geom you plan to use.






share|improve this answer
























  • Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

    – Adhi R.
    Nov 21 '18 at 22:38













  • The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

    – jrnold
    Nov 22 '18 at 19:19


















2














themes don't affect lines in geoms, only lines in axes, gridlines, etc. But, you can change the default appearance of geoms using update_geom_defaults().



#specify geom to update, and list attibutes you want to change appearance of
update_geom_defaults("line", list(size = 1.75))

#now your graph will plot with the line size you defined as default
economics %>%
ggplot(aes(date, uempmed)) +
geom_line()


If you add update_geom_defaults("line", list(size = 1.75)) to the file where you store your custom theme, your geom defaults will also update when you source() your mycustomtheme.r file, and you'll get the linetype you want. Note that setting defaults this way only changes the exact geom specified (line), and does not affect line elements in other geoms (boxplot borders, error bars, etc.), so you will need to define geom defaults for each individual geom you plan to use.






share|improve this answer
























  • Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

    – Adhi R.
    Nov 21 '18 at 22:38













  • The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

    – jrnold
    Nov 22 '18 at 19:19
















2












2








2







themes don't affect lines in geoms, only lines in axes, gridlines, etc. But, you can change the default appearance of geoms using update_geom_defaults().



#specify geom to update, and list attibutes you want to change appearance of
update_geom_defaults("line", list(size = 1.75))

#now your graph will plot with the line size you defined as default
economics %>%
ggplot(aes(date, uempmed)) +
geom_line()


If you add update_geom_defaults("line", list(size = 1.75)) to the file where you store your custom theme, your geom defaults will also update when you source() your mycustomtheme.r file, and you'll get the linetype you want. Note that setting defaults this way only changes the exact geom specified (line), and does not affect line elements in other geoms (boxplot borders, error bars, etc.), so you will need to define geom defaults for each individual geom you plan to use.






share|improve this answer













themes don't affect lines in geoms, only lines in axes, gridlines, etc. But, you can change the default appearance of geoms using update_geom_defaults().



#specify geom to update, and list attibutes you want to change appearance of
update_geom_defaults("line", list(size = 1.75))

#now your graph will plot with the line size you defined as default
economics %>%
ggplot(aes(date, uempmed)) +
geom_line()


If you add update_geom_defaults("line", list(size = 1.75)) to the file where you store your custom theme, your geom defaults will also update when you source() your mycustomtheme.r file, and you'll get the linetype you want. Note that setting defaults this way only changes the exact geom specified (line), and does not affect line elements in other geoms (boxplot borders, error bars, etc.), so you will need to define geom defaults for each individual geom you plan to use.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 18:37









Jan BoyerJan Boyer

1,0352714




1,0352714













  • Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

    – Adhi R.
    Nov 21 '18 at 22:38













  • The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

    – jrnold
    Nov 22 '18 at 19:19





















  • Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

    – Adhi R.
    Nov 21 '18 at 22:38













  • The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

    – jrnold
    Nov 22 '18 at 19:19



















Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

– Adhi R.
Nov 21 '18 at 22:38







Ah interesting, thanks! Confusing how line and rect don't refer to geoms. The end user is installing my fork of ggthemes though, not source()ing it. Is there a way to have that update either when someone calls library(ggthemes) or theme_mycustomtheme()? Basically I want to make it as easy as possible for the end-user to use and a way of baking in update_geom_defaults() would be really ace!

– Adhi R.
Nov 21 '18 at 22:38















The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

– jrnold
Nov 22 '18 at 19:19







The way ggplot2 works, the aesthetics for geoms are separate from themes. Themes only handle the way the non-data/background aspects of the plot are rendered. Also, there's no reason to fork ggthemes to create a new theme. I suggest creating a new package with the theme for your users to install.

– jrnold
Nov 22 '18 at 19:19






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418209%2fhow-to-set-a-default-line-size-in-a-ggplot2-theme-ggtheme%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents