编辑完整主题ggplot的元素

时间:2018-08-20 22:00:08

标签: r ggplot2 themes

我正在尝试修改ggplot中完整主题的元素(在本例中为theme_classic())。本质上,我想将图例放在其他位置。

如果我尝试这样编辑它:

  

theme_classic(theme_classic(legend.position =   c(0.25,0.9),legend.direction =“水平”)

我得到了错误:

  

未使用的参数(legend.position = c(0.25,0.9),legend.direction =“水平”)

所以看来我无法在完整主题内编辑这些功能。如果我尝试在情节中添加另一个theme()函数,似乎没有任何作用。

最后,我研究了完全描述theme_classic()函数的方法,因此我可以只在theme()下输入它,仅编辑图例元素,但是找不到此信息。我只能找到的是:https://ggplot2.tidyverse.org/reference/ggtheme.html。这使theme_classic()为:

  

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

但是输入

  

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 =“水平”)

给予:

  

is.list(val)中的错误:找不到对象'base_size'

我敢肯定,这里我缺少一些简单的东西,但是找不到有关完整主题的完整描述或有关如何在完整主题中编辑元素的任何信息。

我尝试沿柠檬包(https://www.rdocumentation.org/packages/lemon/versions/0.4.1/topics/reposition_legend)的reposition_legend()路线走,但也无法弄清楚如何使主题水平。

1 个答案:

答案 0 :(得分:0)

答案是简单地使用theme_classic()然后使用+ theme()并在其中编辑图例元素等。

抱歉,我想我尝试过这个。

感谢董。

相关问题