简体   繁体   English

GGPLOT2:调整图标题的字体大小

[英]GGPLOT2: Adjust Font Size of Plot Title

I have This ggplot2 I made up to satisfy these conditions:我制作了这个ggplot2来满足这些条件:

  1. Remove default background that is hash colour to be plain.删除散列颜色的默认背景为纯色。
  2. Make (a) to be the plot title located within the plot area that is not close to the line (automatically).使 (a) 成为位于不靠近线的绘图区域内的绘图标题(自动)。
  3. Make $\\phi = .8$ to be automatically at the head of the line (still within the plot area).使 $\\phi = .8$ 自动位于行首(仍在绘图区域内)。
  4. And sd = 1 to be automatically at the tail of the line.并且 sd = 1 将自动位于行尾。
  5. The four(4) Borderlines to be present.将出现的四 (4) 条边界线。
  6. Gridlines to be a grey colour.网格线为灰色。

. .

## simulate ARIMA(1, 0, 0)
set.seed(799837)
ts <- arima.sim(n = 10, model = list(ar = 0.95, order = c(1, 0, 0)), sd = 10)

gplot <- ggplot(NULL, aes(y = ts, x = seq_along(ts))) + 
  geom_line(color = "#F2AA4CFF") + 
  geom_point(color = "#101820FF") + 
  annotate("text", x = mean(seq_along(ts)), y = max(ts) * 1.1, label = "(a)")+
  annotate("text", x = min(seq_along(ts)), y = max(ts) * 1.1, label = 'paste(~phi~"=.8")', parse = TRUE )+ 
  annotate("text", x= max(seq_along(ts)), y = ts[[max(seq_along(ts))]] * 1.1, label = "sd=1") +
  xlab('Time') + 
  ylab('Series') + 
  theme_bw() +
  theme(axis.text = element_text(size = 40, angle = 0, vjust = 0.0, hjust = 0.0), #y-axis label size
        axis.title = element_text(size = 40), #x-axis label size
        axis.title.x = element_text(angle = 0, hjust = 0.5, vjust = 0.5, size = 40), # x-axis title
        axis.title.y = element_text(angle = 90, hjust = 0.5, vjust = 0.5, size = 40), # y-axis title
        plot.title = element_text(size = 40, margin = margin(t = 25, b = -20, l = 0, r = 0)),
        panel.background = element_blank()) + 
  scale_x_continuous(breaks = seq(1,10,2)) +
  scale_y_continuous(expand = c(0.0, 0.00))
gplot

ggplot2 输出

I want the font of the plot title to increase.我希望情节标题的字体增加。 As you can see that despite setting the font of the plot title to 40 the font title refuse to increase.如您所见,尽管将情节标题的字体设置为 40,但字体标题拒绝增加。 This question is a follow-up question from Remove Default Background Color and Make Title in Plot Zone这个问题是从删除默认背景颜色并在绘图区制作标题的后续问题

Daniel丹尼尔

If (a) is the 'title' it's not really the title, it's an annotation.如果(a)是“标题”,则它不是真正的标题,而是注释。

So to change it's size do it when you add the annotation.因此,要更改其大小,请在添加注释时进行。


annotate("text", x = mean(seq_along(ts)), y = max(ts) * 1.5, label = "(a)", size = 40)

在此处输入图片说明

You might also want to resize the other annotations.您可能还想调整其他注释的大小。

  annotate("text", x = mean(seq_along(ts)), y = max(ts) * 1.5, label = "(a)", size = 40) +
  annotate("text", x = min(seq_along(ts)), y = max(ts) * 1.5, label = 'paste(~phi~"=.8")', parse = TRUE, size = 10)+ 
  annotate("text", x= max(seq_along(ts)), y = ts[[max(seq_along(ts))]] * 1.5, label = "sd=1", size = 10)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM