3  ggplot2常用坐标轴选项汇总

library(ggplot2)
ggplot(mtcars, 
       aes(wt, mpg)
) +
  geom_point()+
  labs(
    x="aaa",     # x轴名称
    y="bbb",     # y轴名称
    title="ccc"  # 标题名称
  )+
  # scale_y_continuous(
  #   breaks = c(0,10,20,30),                   # 设置y轴刻度
  #   labels = c("a","b","c","d")               # 设置y轴对应刻度处显示的名称
  # )+  
  # xlim(1,10)+                                 # 设置x轴显示范围
  # ylim(1,10)+                                 # 设置y轴显示范围
  theme_bw()+                                   # 主题方案
  theme(
    plot.title = element_text(                  # 标题
      size = 10,        # 字体大小
      face = "bold",    # 字体样式 bold 表示粗体
      colour = "red",   # 字体颜色
      # family = "RMN", # 字体型号 需要提前定义windowsFonts,见程序末尾
      hjust = 0.5),     # 位置 0.5表示居中
    plot.subtitle = element_text(size =10,      # 副标题
                                 face = "bold",
                                 hjust = 0.5),
    axis.title.y = element_text(size = 10,      # y轴标题
                                face = "bold",
                                hjust = 0.5),
    axis.title.x = element_text(size = 10,      # x轴标题
                                face = "bold",
                                hjust = 0.5),
    axis.text.x = element_text(size = 10,       # x轴刻度文字
                               angle = 0, 
                               hjust = 0.5),
    axis.text.y = element_text(size = 10,       # y轴刻度文字
                               angle = 0,
                               vjust = 0.5),
    # axis.ticks = element_blank(),             # 刻度参数
    legend.position = "right",                  # 图例位置
    legend.text = element_text(size = 10),      # 图例文字
    legend.title = element_text(size = 10),     # 图例标题
    legend.key.size = unit(10, "pt")            # 图例图案
  )

windowsFonts(  # 定义字体
  RMN=windowsFont("Times New Roman"),
  ARL=windowsFont("Arial"))