如何在 y 轴标签上方启动 ggplot 标题? [重复]

问题描述 投票:0回答:1

有时我的 y 轴标签很长,这会导致标题开始位置太靠右。如何在 y 轴标签上方开始我的 ggplot 标题,而不是从 y 轴标签右侧开始?

library(tidyverse)

mtcars |> 
    rownames_to_column('model') |> 
    ggplot(aes(x=model, y = mpg)) +
    geom_col() +
    coord_flip() +
    labs(title = 'How can I start this title in the upper left corner above the model labels?')

r ggplot2
1个回答
0
投票

像这样添加这个函数

scale_y_discrete(position='right')

library(tidyverse)

mtcars |> 
  rownames_to_column('model') |> 
  ggplot(aes(x=model, y = mpg)) +
  geom_col() +
  coord_flip() +
  labs(title = 'How can I start this title in the upper left corner above the model labels?')+
  scale_y_discrete(position = "right")
© www.soinside.com 2019 - 2024. All rights reserved.