美文网首页
R语言可视化及作图9--主题函数

R语言可视化及作图9--主题函数

作者: Hayley笔记 | 来源:发表于2021-04-28 08:58 被阅读0次

    R语言绘图系列:


    一. 主题函数

    1. ggtheme {ggplot2}

    1.1 绘制一张题

    library(ggplot2)
    mg <- ggplot(mtcars,aes(x=mpg,y=wt))+geom_point()
    mg  #默认灰色背景
    

    1.2 theme_bw函数

    a <- mg+theme_bw()+geom_text(aes(x=30,y=5),label='theme_bw()',color=
                                   'red',size=10)
    a #白色网格背景
    

    1.3 theme_classic函数

    b <- mg+theme_classic()+geom_text(aes(x=25,y=5),label='theme_classic()',
                                      color='red',size=10)
    b #经典白色背景
    

    1.4 theme_dark

    c <- mg+theme_dark()+geom_text(aes(x=25,y=5),label='theme_dark()',
                                      color='red',size=10)
    c #暗色背景
    

    1.5 theme_light函数

    d <- mg+theme_light()+geom_text(aes(x=25,y=5),label='theme_light()',
                                   color='red',size=10)
    d
    

    1.6 theme_get函数

    e <- mg+theme_get()+geom_text(aes(x=25,y=5),label='theme_get()',
                                    color='red',size=10)
    e#与原始背景类似
    

    1.7 theme_linedraw函数

    f <- mg+theme_linedraw()+geom_text(aes(x=25,y=5),label='theme_linedraw()',
                                  color='red',size=10)
    f
    

    1.8 theme_replace

    g <- mg+theme_replace()+geom_text(aes(x=25,y=5),label='theme_replace()',
                                       color='red',size=10)
    g #与默认类似
    

    1.9 theme_minimal

    h <- mg+theme_minimal()+geom_text(aes(x=25,y=5),label='theme_minimal()',
                                      color='red',size=10)
    h #x轴y轴不见了,只有网格
    

    1.10 theme_void

    i <- mg+theme_void()+geom_text(aes(x=25,y=5),label='theme_void()',
                                      color='red',size=10)
    i #只有点
    
    2. ggthemes包

    绘制一张图

    library(ggplot2)
    library(ggthemes)
    p <- ggplot(mtcars,aes(x=wt,y=mpg,color=factor(gear)))+
      geom_point()+labs(title = 'Cars')+
      theme(plot.title = element_text(hjust = 0.5,family = 'Times New Roman'))
    p
    

    2.1 theme_economist

    a <- p+theme_economist()+scale_color_economist()+
      geom_text(aes(x=4,y=30),label='theme_economics',color='deeppink')
    a
    

    2.2 theme_solarized

    b <- p+theme_solarized()+scale_color_solarized('blue')+
      geom_text(aes(x=4,y=30),label='theme_solarized',color='deeppink')
    b
    

    2.3 theme_dark

    c <- p+theme_solarized(light = FALSE)+scale_color_solarized('red')+
      geom_text(aes(x=4,y=30),label='theme_dark',color='deeppink')
    c
    

    2.4 theme_dark2

    d <- p+theme_solarized_2(light = FALSE)+scale_color_solarized('blue')+
      geom_text(aes(x=4,y=30),label='theme_dark2',color='deeppink')
    d
    

    2.5 theme_stata

    e <- p+theme_stata()+scale_color_stata()+
      geom_text(aes(x=4,y=30),label='theme_stata',color='deeppink')
    e #模仿stata生成的图
    

    2.6 theme_igray

    f <- p+theme_igray()+geom_text(aes(x=4,y=30),label='theme_igray',color='deeppink')
    f
    

    2.7 theme_wsj

    h <- p+theme_wsj()+scale_color_wsj('colors6','')+
      geom_text(aes(x=4,y=30),label='theme_wsj',color='deeppink')
    h
    

    2.8 theme_calc

    i <- p+theme_calc()+scale_color_calc()+
      geom_text(aes(x=4,y=30),label='theme_calc',color='deeppink')
    i
    

    2.9 theme_pander

    j <- p+theme_pander()+scale_color_pander()+
      geom_text(aes(x=4,y=30),label='theme_pander',color='deeppink')
    j
    

    2.10 theme_hc

    k <- p+theme_hc()+scale_color_hc()+
      geom_text(aes(x=4,y=30),label='theme_hc',color='deeppink')
    k
    

    相关文章

      网友评论

          本文标题:R语言可视化及作图9--主题函数

          本文链接:https://www.haomeiwen.com/subject/tetyrltx.html