MorrisseyJ
MorrisseyJ

Reputation: 1271

Edit elements of complete theme ggplot

I am trying to amend an element of a complete theme in ggplot (theme_classic() in this instance). Essentially I want to put the legend in a different place.

If i try and edit this as such:

theme_classic(theme_classic(legend.position = c(0.25,0.9), legend.direction = "horizontal")

i get the error:

unused arguments (legend.position = c(0.25, 0.9), legend.direction = "horizontal")

So it seems i can't edit these features within the complete theme. If i try adding another theme() function to the plot it doesn't seem to do anything.

Finally, I looked into describing the theme_classic() function entirely, so that i could simply enter this under theme(), editing just the legend elements, however I couldn't find this information. All i could find was this: https://ggplot2.tidyverse.org/reference/ggtheme.html. Which gives theme_classic() as:

theme_classic(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22)

But entering

theme(base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22, legend.position = c(0.25, 0.9), legend.direction = "horizontal")

gives:

Error in is.list(val) : object 'base_size' not found

I am sure i am missing something simple here, but can't find any information on either the full description of the complete themes, or about how to edit an element within a complete theme.

I tried going down the reposition_legend() route from the lemon package (https://www.rdocumentation.org/packages/lemon/versions/0.4.1/topics/reposition_legend), but couldn't work out how to make the theme horizontal as well.

Upvotes: 2

Views: 1369

Answers (1)

MorrisseyJ
MorrisseyJ

Reputation: 1271

Answer was to simply use theme_classic() and then + theme() and edit the legend elements etc. in there.

Apologies, i thought i tried this.

Thanks to Tung.

Upvotes: 1

Related Questions